Skip to content

Commit

Permalink
Refactor waitForOpen
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrange committed Apr 24, 2023
1 parent 18c761b commit ffb3fdf
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions hydra-node/test/Hydra/Model.hs
Original file line number Diff line number Diff line change
Expand Up @@ -620,25 +620,17 @@ performNewTx party tx = do
waitForOpen :: MonadDelay m => TestHydraNode tx m -> RunMonad m ()
waitForOpen node = do
outs <- lift $ serverOutputs node
go outs
if isOpen False outs
then pure ()
else waitAndRetry
where
go = \case
[] -> waitAndRetry
(x : xs) -> case x of
HeadIsOpen{}
| not $ containsRolledBack xs -> found
_ -> go xs

containsRolledBack = any matchRolledBack

found = pure ()
isOpen status [] = status
isOpen _ (HeadIsOpen{} : rest) = isOpen True rest
isOpen _ (RolledBack{} : rest) = isOpen False rest
isOpen status (_ : rest) = isOpen status rest

waitAndRetry = lift (threadDelay 0.1) >> waitForOpen node

matchRolledBack = \case
RolledBack{} -> True
_ -> False

sendsInput :: (MonadSTM m, MonadThrow m) => Party -> ClientInput Tx -> RunMonad m ()
sendsInput party command = do
nodes <- gets nodes
Expand Down

0 comments on commit ffb3fdf

Please sign in to comment.