on master help sign in
More complicated logging tests
commitafbd289a8935694729a1d4709acb11afbf21dab8 authorHarendra Kumar <harendra.kumar@gmail.com> dateThu 29 Jun 2017, 05:21 (9 years ago) parent760a298
2 files changed+28−6
test/3-waitEvents.hs+13 test/logged.hs+15−6
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 ((<$>), (<*>), (<|>))
24import Control.Monad.IO.Class (liftIO)
5+import System.IO
6+import Strands
37
48main = do
5− logs <- waitLogged comp
9+ hSetBuffering stdout LineBuffering
10+ logs <- waitLogged_ comp
611
712 putStrLn $ "\nResuming with logs:"
8− logs1 <- waitLogged $ eachWithLog comp logs
13+ logs1 <- waitLogged_ $ eachWithLog comp logs
914
1015 putStrLn $ "\nResuming with logs:"
11− logs2 <- waitLogged $ eachWithLog comp logs1
16+ logs2 <- waitLogged_ $ eachWithLog comp logs1
1217
1318 putStrLn $ "\nLogs at the end must be empty:"
1419 putStrLn $ show logs2
1520
1621 putStrLn $ "\nRunning the last log again using wait:"
17− wait $ eachWithLog comp logs1
22+ wait_ $ eachWithLog comp logs1
1823
1924 where
25+
2026 comp = logged $ threads 5 $ do
2127 r <- logged $ each [1..3]
2228 logged $ liftIO $ print ("A",r)
2329 suspend
2430 logged $ liftIO $ print ("B",r)
31+ x <- logged $ (,) <$> (event 1 <|> event 2) <*> (event 3 <|> event 4)
2532 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)