Skip to content

Commit ad7096d

Browse files
jasagredobolt12
authored andcommitted
Add regression test
1 parent 13fa0cf commit ad7096d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

io-sim/test/Test/Control/Concurrent/Class/MonadMVar.hs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Test.Control.Concurrent.Class.MonadMVar where
88
import Control.Concurrent.Class.MonadMVar
99
import Control.Monad.Class.MonadAsync
1010
import Control.Monad.Class.MonadFork
11+
import Control.Monad.Class.MonadTest
1112
import Control.Monad.Class.MonadTime.SI
1213
import Control.Monad.Class.MonadTimer.SI
1314
import Data.Bifoldable (bifoldMap)
@@ -64,6 +65,7 @@ tests =
6465
[ testCase "empty MVar is empty" unit_isEmptyMVar_empty_sim
6566
, testCase "full MVar is not empty" unit_isEmptyMVar_full_sim
6667
]
68+
, testProperty "takeMVar is exception safe" prop_takeMVar_exception_safe
6769
]
6870

6971

@@ -310,6 +312,29 @@ unit_isEmptyMVar_full_sim =
310312
assertBool "full mvar must not be empty" $
311313
runSimOrThrow (prop_isEmptyMVar False)
312314

315+
--
316+
-- takeMVar is exception safe
317+
--
318+
prop_takeMVar_exception_safe :: Property
319+
prop_takeMVar_exception_safe =
320+
exploreSimTrace id (do
321+
exploreRaces
322+
mv <- newMVar (0 :: Int)
323+
t1 <- async $ void $ withMVar mv (\v -> pure (v + 1, ()))
324+
t2 <- async $ void $ do
325+
_ <- withMVar mv (\v -> pure (v + 1, ()))
326+
withMVar mv (\v -> pure (v + 1, ()))
327+
t3 <- async $ cancel t1
328+
wait t3
329+
wait t2
330+
wait t1
331+
) (\_ trace ->
332+
case traceResult False trace of
333+
Left FailureDeadlock{} ->
334+
counterexample (ppTrace trace) $ property False
335+
_ -> property True
336+
)
337+
313338
--
314339
-- Utils
315340
--

0 commit comments

Comments
 (0)