File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -149,9 +149,7 @@ tryReadTBQueueDefault (TBQueue queue _size) = do
149
149
return (Just x)
150
150
[] ->
151
151
case reverse ys of
152
- [] -> do
153
- writeTVar queue $! (xs, r', ys, w)
154
- return Nothing
152
+ [] -> return Nothing
155
153
156
154
-- NB. lazy: we want the transaction to be
157
155
-- short, otherwise it will conflict
Original file line number Diff line number Diff line change @@ -192,6 +192,10 @@ tests =
192
192
, testProperty " maintains FIFO order IO" prop_flushTBQueueOrder_IO
193
193
, testProperty " maintains FIFO order IOSim" prop_flushTBQueueOrder_IOSim
194
194
]
195
+ , testGroup " tryReadTBQueue"
196
+ [ testProperty " works correctly when the queue is empty IO" prop_tryReadEmptyTBQueue_IO
197
+ , testProperty " works correctly when the queue is empty IOSim" prop_tryReadEmptyTBQueue_IOSim
198
+ ]
195
199
]
196
200
]
197
201
@@ -1464,6 +1468,24 @@ writeAndFlushTBQueue entries =
1464
1468
forM_ entries $ writeTBQueue q
1465
1469
flushTBQueue q
1466
1470
1471
+ prop_tryReadEmptyTBQueue_IO :: Bool -> Property
1472
+ prop_tryReadEmptyTBQueue_IO sndRead =
1473
+ ioProperty $ tryReadEmptyTBQueue sndRead
1474
+
1475
+ prop_tryReadEmptyTBQueue_IOSim :: Bool -> Property
1476
+ prop_tryReadEmptyTBQueue_IOSim sndRead =
1477
+ runSimOrThrow $ tryReadEmptyTBQueue sndRead
1478
+
1479
+ tryReadEmptyTBQueue :: MonadSTM m => Bool -> m Property
1480
+ tryReadEmptyTBQueue sndRead = atomically $ do
1481
+ q <- newTBQueue 10
1482
+ _ <- tryReadTBQueue q
1483
+ writeTBQueue q ()
1484
+ when sndRead $ void $ tryReadTBQueue q
1485
+ l <- lengthTBQueue q
1486
+
1487
+ pure $ l === if sndRead then 0 else 1
1488
+
1467
1489
--
1468
1490
-- Utils
1469
1491
--
You can’t perform that action at this time.
0 commit comments