Skip to content

Commit

Permalink
Use TQueue instead of TMVar for responses in test
Browse files Browse the repository at this point in the history
TMVar blocks client and server
  • Loading branch information
abailly-iohk committed Jun 16, 2021
1 parent fa791bd commit 44b863c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions hydra-node/test/Hydra/BehaviorSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import Control.Monad.Class.MonadSTM (
atomically,
modifyTVar,
modifyTVar',
newEmptyTMVarIO,
newTQueue,
newTVarIO,
putTMVar,
readTQueue,
readTVar,
takeTMVar,
writeTQueue,
)
import Control.Monad.Class.MonadThrow (MonadThrow)
import Control.Monad.Class.MonadTimer (DiffTime, MonadTimer, threadDelay, timeout)
Expand Down Expand Up @@ -286,14 +286,14 @@ withHydraNode ::
(TestHydraNode MockTx (IOSim s) -> IOSim s a) ->
IOSim s a
withHydraNode nodeId snapshotStrategy connectToChain action = do
response <- newEmptyTMVarIO
response <- atomically newTQueue
node <- createHydraNode response

withAsync (runHydraNode traceInIOSim node) $ \_ ->
action $
TestHydraNode
{ sendRequest = handleClientRequest node
, waitForResponse = atomically $ takeTMVar response
, waitForResponse = atomically $ readTQueue response
, nodeId
}
where
Expand All @@ -303,7 +303,7 @@ withHydraNode nodeId snapshotStrategy connectToChain action = do
let headState = createHeadState [] (HeadParameters testContestationPeriod mempty)
hh <- createHydraHead headState mockLedger
let hn' = Network{broadcast = const $ pure ()}
let node = HydraNode{eq, hn = hn', hh, oc = OnChain (const $ pure ()), sendResponse = atomically . putTMVar response, env}
let node = HydraNode{eq, hn = hn', hh, oc = OnChain (const $ pure ()), sendResponse = atomically . writeTQueue response, env}
connectToChain node

-- | A 'Tracer' that works in 'IOSim' monad.
Expand Down

0 comments on commit 44b863c

Please sign in to comment.