File tree Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 1
1
# Revision history of io-sim
2
2
3
+ ## Next release
4
+
5
+ - Fixed ` tryReadTBQueue ` when returning ` Nothing ` .
6
+
3
7
## 1.5.1.0
4
8
5
9
- The signature of:
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 @@ -184,6 +184,10 @@ tests =
184
184
[ testProperty " empties the queue" prop_flushTQueueEmpties
185
185
, testProperty " maintains FIFO order" prop_flushTQueueOrder
186
186
]
187
+ , testGroup " tryReadTBQueue"
188
+ [ testProperty " works correctly when the queue is empty IO" prop_tryReadEmptyTBQueue_IO
189
+ , testProperty " works correctly when the queue is empty IOSim" prop_tryReadEmptyTBQueue_IOSim
190
+ ]
187
191
]
188
192
]
189
193
@@ -1412,6 +1416,24 @@ writeAndFlushQueue entries =
1412
1416
forM_ entries $ writeTQueue q
1413
1417
flushTQueue q
1414
1418
1419
+ prop_tryReadEmptyTBQueue_IO :: Bool -> Property
1420
+ prop_tryReadEmptyTBQueue_IO sndRead =
1421
+ ioProperty $ tryReadEmptyTBQueue sndRead
1422
+
1423
+ prop_tryReadEmptyTBQueue_IOSim :: Bool -> Property
1424
+ prop_tryReadEmptyTBQueue_IOSim sndRead =
1425
+ runSimOrThrow $ tryReadEmptyTBQueue sndRead
1426
+
1427
+ tryReadEmptyTBQueue :: MonadSTM m => Bool -> m Property
1428
+ tryReadEmptyTBQueue sndRead = atomically $ do
1429
+ q <- newTBQueue 10
1430
+ _ <- tryReadTBQueue q
1431
+ writeTBQueue q ()
1432
+ when sndRead $ void $ tryReadTBQueue q
1433
+ l <- lengthTBQueue q
1434
+
1435
+ pure $ l === if sndRead then 0 else 1
1436
+
1415
1437
--
1416
1438
-- Utils
1417
1439
--
You can’t perform that action at this time.
0 commit comments