@@ -181,8 +181,16 @@ tests =
181
181
]
182
182
, testGroup " MonadSTM"
183
183
[ testGroup " flushTQueue"
184
- [ testProperty " empties the queue" prop_flushTQueueEmpties
185
- , testProperty " maintains FIFO order" prop_flushTQueueOrder
184
+ [ testProperty " empties the queue IO" prop_flushTQueueEmpties_IO
185
+ , testProperty " empties the queue IOSim" prop_flushTQueueEmpties_IOSim
186
+ , testProperty " maintains FIFO order IO" prop_flushTQueueOrder_IO
187
+ , testProperty " maintains FIFO order IOSim" prop_flushTQueueOrder_IOSim
188
+ ]
189
+ , testGroup " flushTBQueue"
190
+ [ testProperty " empties the queue IO" prop_flushTBQueueEmpties_IO
191
+ , testProperty " empties the queue IOSim" prop_flushTBQueueEmpties_IOSim
192
+ , testProperty " maintains FIFO order IO" prop_flushTBQueueOrder_IO
193
+ , testProperty " maintains FIFO order IOSim" prop_flushTBQueueOrder_IOSim
186
194
]
187
195
]
188
196
]
@@ -1385,33 +1393,77 @@ prop_registerDelayCancellable_IO =
1385
1393
cancelTimeout
1386
1394
awaitTimeout
1387
1395
1388
- -- | Test that 'flushTQueue' empties the queue.
1389
- prop_flushTQueueEmpties :: Property
1390
- prop_flushTQueueEmpties =
1391
- ioProperty emptyQueueAfterFlush
1392
- .&&. runSimOrThrow emptyQueueAfterFlush
1396
+ -- | Test that 'flushTQueue' empties the queue in `IO`.
1397
+ prop_flushTQueueEmpties_IO :: Property
1398
+ prop_flushTQueueEmpties_IO =
1399
+ ioProperty emptyTQueueAfterFlush
1400
+
1401
+ -- | Test that 'flushTQueue' empties the queue in `IOSim`.
1402
+ prop_flushTQueueEmpties_IOSim :: Bool
1403
+ prop_flushTQueueEmpties_IOSim =
1404
+ runSimOrThrow emptyTQueueAfterFlush
1393
1405
1394
- emptyQueueAfterFlush :: MonadSTM m => m Bool
1395
- emptyQueueAfterFlush = do
1406
+ emptyTQueueAfterFlush :: MonadSTM m => m Bool
1407
+ emptyTQueueAfterFlush = do
1396
1408
q <- newTQueueIO
1397
1409
atomically $ do
1398
1410
writeTQueue q (1 :: Int )
1399
1411
_ <- flushTQueue q
1400
1412
isEmptyTQueue q
1401
1413
1402
- -- | Test that 'flushTQueue' returns values in FIFO order.
1403
- prop_flushTQueueOrder :: [Int ] -> Property
1404
- prop_flushTQueueOrder entries =
1405
- ioProperty (writeAndFlushQueue entries >>= \ actual -> pure $ actual === entries)
1406
- .&&. runSimOrThrow (writeAndFlushQueue entries) === entries
1414
+ -- | Test that 'flushTQueue' returns values in FIFO order in `IO`.
1415
+ prop_flushTQueueOrder_IO :: [Int ] -> Property
1416
+ prop_flushTQueueOrder_IO entries =
1417
+ ioProperty (writeAndFlushTQueue entries >>= \ actual -> pure $ actual === entries)
1407
1418
1408
- writeAndFlushQueue :: MonadSTM m => [Int ] -> m [Int ]
1409
- writeAndFlushQueue entries =
1419
+ -- | Test that 'flushTQueue' returns values in FIFO order in `IOSim`.
1420
+ prop_flushTQueueOrder_IOSim :: [Int ] -> Property
1421
+ prop_flushTQueueOrder_IOSim entries =
1422
+ runSimOrThrow (writeAndFlushTQueue entries) === entries
1423
+
1424
+ writeAndFlushTQueue :: MonadSTM m => [Int ] -> m [Int ]
1425
+ writeAndFlushTQueue entries =
1410
1426
atomically $ do
1411
1427
q <- newTQueue
1412
1428
forM_ entries $ writeTQueue q
1413
1429
flushTQueue q
1414
1430
1431
+ -- | Test that 'flushTBQueue' empties the queue in `IO`.
1432
+ prop_flushTBQueueEmpties_IO :: Property
1433
+ prop_flushTBQueueEmpties_IO =
1434
+ ioProperty emptyTBQueueAfterFlush
1435
+
1436
+ -- | Test that 'flushTBQueue' empties the queue in `IOSim`.
1437
+ prop_flushTBQueueEmpties_IOSim :: Bool
1438
+ prop_flushTBQueueEmpties_IOSim =
1439
+ runSimOrThrow emptyTBQueueAfterFlush
1440
+
1441
+ emptyTBQueueAfterFlush :: MonadSTM m => m Bool
1442
+ emptyTBQueueAfterFlush = do
1443
+ q <- newTBQueueIO 10
1444
+ atomically $ do
1445
+ writeTBQueue q (1 :: Int )
1446
+ writeTBQueue q 2
1447
+ _ <- flushTBQueue q
1448
+ isEmptyTBQueue q
1449
+
1450
+ -- | Test that 'flushTBQueue' returns values in FIFO order in `IO`.
1451
+ prop_flushTBQueueOrder_IO :: [Int ] -> Property
1452
+ prop_flushTBQueueOrder_IO entries =
1453
+ ioProperty (writeAndFlushTBQueue entries >>= \ actual -> pure $ actual === entries)
1454
+
1455
+ -- | Test that 'flushTBQueue' returns values in FIFO order in `IOSim`.
1456
+ prop_flushTBQueueOrder_IOSim :: [Int ] -> Property
1457
+ prop_flushTBQueueOrder_IOSim entries =
1458
+ runSimOrThrow (writeAndFlushTBQueue entries) === entries
1459
+
1460
+ writeAndFlushTBQueue :: MonadSTM m => [Int ] -> m [Int ]
1461
+ writeAndFlushTBQueue entries =
1462
+ atomically $ do
1463
+ q <- newTBQueue (1 + fromIntegral (length entries))
1464
+ forM_ entries $ writeTBQueue q
1465
+ flushTBQueue q
1466
+
1415
1467
--
1416
1468
-- Utils
1417
1469
--
0 commit comments