Skip to content

Commit 57e1304

Browse files
authored
Merge pull request #1275 from input-output-hk/fix-mockchain-tqueue-flush
Fix tqueue flushing in Mockchain
2 parents f7692d5 + 2919a4a commit 57e1304

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

hydra-node/test/Hydra/Model/MockChain.hs

+13-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import Cardano.Binary (serialize', unsafeDeserialize')
1010
import Control.Concurrent.Class.MonadSTM (
1111
MonadLabelledSTM,
1212
MonadSTM (newTVarIO, writeTVar),
13-
flushTQueue,
1413
labelTQueueIO,
1514
labelTVarIO,
1615
modifyTVar,
1716
newTQueueIO,
1817
newTVarIO,
1918
readTVarIO,
19+
tryReadTQueue,
2020
writeTQueue,
2121
writeTVar,
2222
)
@@ -195,7 +195,7 @@ mockChainAndNetwork tr seedKeys commits = do
195195
rollForward nodes chain queue = do
196196
threadDelay blockTime
197197
atomically $ do
198-
transactions <- flushTQueue queue
198+
transactions <- flushQueue queue
199199
addNewBlockToChain chain transactions
200200
doRollForward nodes chain
201201

@@ -328,3 +328,14 @@ mkMockTxIn vk ix = TxIn (TxId tid) (TxIx ix)
328328
where
329329
-- NOTE: Ugly, works because both binary representations are 32-byte long.
330330
tid = unsafeDeserialize' (serialize' vk)
331+
332+
-- NOTE: This is a workaround until the upstream PR is merged:
333+
-- https://github.com/input-output-hk/io-sim/issues/133
334+
flushQueue :: MonadSTM m => TQueue m a -> STM m [a]
335+
flushQueue queue = go []
336+
where
337+
go as = do
338+
hasA <- tryReadTQueue queue
339+
case hasA of
340+
Just a -> go (a : as)
341+
Nothing -> pure as

0 commit comments

Comments
 (0)