1module AsyncTests (asyncTests) where
3import Control.Concurrent (threadDelay)
5import Control.Monad.IO.Class
8import qualified Data.Set as S
12import Effectful.State.Dynamic
14import qualified Utils as U
17asyncTests = testGroup "Async"
18 [ testCase "local state" test_localState
19 , testCase "shared state" test_sharedState
20 , testCase "error handling" test_errorHandling
23test_localState :: Assertion
24test_localState = runIOE . runAsyncE . evalState x $ do
25 replicateConcurrently_ 2 $ do
27 U.assertEqual "expected result" x r
32 goDownward :: State Int :> es => Int -> Eff es Int
34 end <- state @Int $ \case
39 else goDownward $ acc + 1
41test_sharedState :: Assertion
42test_sharedState = runIOE . runAsyncE . evalStateMVar (S.empty @Int) $ do
43 concurrently_ (addWhen even x) (addWhen odd x)
44 U.assertEqual "expected result" (S.fromList [1..x]) =<< get
49 addWhen :: State (S.Set Int) :> es => (Int -> Bool) -> Int -> Eff es ()
57test_errorHandling :: Assertion
58test_errorHandling = runIOE . runAsyncE . evalStateMVar (0::Int) $ do
59 r <- runError $ concurrently_
60 (liftIO (threadDelay 10000) >> throwError err)
63 Left (_, e) -> U.assertEqual "error caught" err e
64 Right _ -> U.assertFailure "error not caught"
65 U.assertEqual "state updated" x =<< get
71 err = "thrown from async"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list