on master help sign in
More complicated logging tests
afbd289Harendra Kumar
test/3-waitEvents.hsnew file+13
@@ -0,0 +1,13 @@
1+import Control.Concurrent (threadDelay, myThreadId)
2+import Control.Monad.IO.Class (liftIO)
3+import System.Random (randomIO)
4+import System.IO
5+
6+import Strands
7+
8+--- Check space leaks
9+
10+main = wait_ $ do
11+ x <- waitEvents (randomIO :: IO Int)
12+ y <- waitEvents (randomIO :: IO Int)
13+ return (x, y)
test/logged.hs+15−6
@@ -1,26 +1,35 @@
1−import Strands
1+{-# LANGUAGE FlexibleContexts #-}
2+
3+import Control.Applicative ((<$>), (<*>), (<|>))
2import Control.Monad.IO.Class (liftIO)
4import Control.Monad.IO.Class (liftIO)
5+import System.IO
6+import Strands
3
7
4main = do
8main = do
9+ hSetBuffering stdout LineBuffering
5− logs <- waitLogged comp
10+ logs <- waitLogged_ comp
6
11
7 putStrLn $ "\nResuming with logs:"
12 putStrLn $ "\nResuming with logs:"
8− logs1 <- waitLogged $ eachWithLog comp logs
13+ logs1 <- waitLogged_ $ eachWithLog comp logs
9
14
10 putStrLn $ "\nResuming with logs:"
15 putStrLn $ "\nResuming with logs:"
11− logs2 <- waitLogged $ eachWithLog comp logs1
16+ logs2 <- waitLogged_ $ eachWithLog comp logs1
12
17
13 putStrLn $ "\nLogs at the end must be empty:"
18 putStrLn $ "\nLogs at the end must be empty:"
14 putStrLn $ show logs2
19 putStrLn $ show logs2
15
20
16 putStrLn $ "\nRunning the last log again using wait:"
21 putStrLn $ "\nRunning the last log again using wait:"
17− wait $ eachWithLog comp logs1
22+ wait_ $ eachWithLog comp logs1
18
23
19 where
24 where
25+
20 comp = logged $ threads 5 $ do
26 comp = logged $ threads 5 $ do
21 r <- logged $ each [1..3]
27 r <- logged $ each [1..3]
22 logged $ liftIO $ print ("A",r)
28 logged $ liftIO $ print ("A",r)
23 suspend
29 suspend
24 logged $ liftIO $ print ("B",r)
30 logged $ liftIO $ print ("B",r)
31+ x <- logged $ (,) <$> (event 1 <|> event 2) <*> (event 3 <|> event 4)
25 suspend
32 suspend
26− liftIO $ print ("C",r)
33+ liftIO $ print ("C", r, x)
34+
35+ event n = async (do putStrLn ("event" ++ show n); return n :: IO Int)