hedgehog-extras-0.6.0.0: Supplemental library for hedgehog
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hedgehog.Extras.Test.Concurrent

Description

This modules provides concurrency abstractions for hedgehog tests. Using "lifted-base" one can execute expensive test actions concurrently.

For example, the actions invoked inside mapConcurrently_ are invoked in the same MonadTest as the outer monad of mapConcurrently_.

import qualified Hedgehog.Extras.Test.Concurrent as H

setUpEnvironment = H.mapConcurrently_ id
  [ H.threadDelay 100 >> pure 1
  , H.threadDelay 200 >> pure 2
  , H.threadDelay 300 >> pure 3
  ]

Warning: Do not use this module for running concurrent checks! The MonadBaseControl instance does not aggregate effects for PropertyT. Consider the following code:

  LA.mapConcurrently_ id
    [ do
      H.note_ "FAIL1"
      success
    , do
      IO.threadDelay 1_000_000
      H.note_ "FAIL2"
      failure
    , do
      H.note_ "FAIL3"
      failure
    ]

Executing this code will give you the following output in the test report:

66 ┃   LA.mapConcurrently_ id
67 ┃     [ do
68 ┃       H.note_ "FAIL1"
   ┃       │ FAIL1
69 ┃       success
70 ┃     , do
71 ┃       IO.threadDelay 1_000_000
72 ┃       H.note_ "FAIL2"
   ┃       │ FAIL2
73 ┃       failure
   ┃       ^^^^^^^
74 ┃     , do
75 ┃       H.note_ "FAIL3"
76 ┃       failure
77 ┃     ]

Please note that only FAIL1 and FAIL2 annotations were reported - FAIL3 annotation and the failure below was swallowed without any information.

Don't use concurrency abstractions from this module, when you need to aggregate and report failures!

Synopsis

Documentation

threadDelay :: (MonadTest m, MonadIO m) => Int -> m () Source #

Delay the thread by n milliseconds.

Re-exports of concurrency abstractions from lifted-base

Orphan instances

MonadBaseControl IO (ResourceT IO) Source # 
Instance details

Associated Types

type StM (ResourceT IO) a #

MonadBase IO (ResourceT IO) Source # 
Instance details

Methods

liftBase :: IO α -> ResourceT IO α #