on master help sign in
Add a test case for concurrent applicative
commit5add04dd8d412b3c19f6733a001e702c76a83578 authoradithyaov <adithya@composewell.com> dateThu 9 Dec 2021, 01:45 (5 years ago) parentf51025b
1 file changed+15−1
test/Streamly/Test/Prelude/Async.hs+15−1
test/Streamly/Test/Prelude/Async.hs+15−1
@@ -9,6 +9,7 @@
99
1010module Streamly.Test.Prelude.Async where
1111
12+import Control.Concurrent (threadDelay)
1213import Data.List (sort)
1314#if __GLASGOW_HASKELL__ < 808
1415import Data.Semigroup ((<>))
@@ -19,10 +20,22 @@ import Test.Hspec as H
1920import Streamly.Prelude
2021import qualified Streamly.Prelude as S
2122
23+import Data.IORef
2224import Streamly.Test.Prelude.Common
2325
2426moduleName :: String
25−moduleName = "Prelude.Ahead"
27+moduleName = "Prelude.Async"
28+
29+concurrentApplicative :: IO ()
30+concurrentApplicative = do
31+ ref <- newIORef []
32+ let action i = modifyIORef ref (++ [i]) >> return (i :: Int)
33+ s1 = S.fromEffect (threadDelay 2000000 >> action 1)
34+ s2 = S.fromEffect (threadDelay 1000000 >> action 2)
35+ res <- S.toList $ S.fromZipAsync $ (,) <$> s1 <*> s2
36+ refVal <- readIORef ref
37+ res `shouldBe` [(1, 2)]
38+ refVal `shouldBe` [2, 1]
2639
2740main :: IO ()
2841main = hspec
@@ -75,6 +88,7 @@ main = hspec
7588 asyncOps $ prop "zip applicative asyncly folded" . zipAsyncApplicative folded (==)
7689 asyncOps $ prop "zip monadic asyncly" . zipAsyncMonadic S.fromFoldable (==)
7790 asyncOps $ prop "zip monadic asyncly folded" . zipAsyncMonadic folded (==)
91+ it "zip monadic asyncly order" concurrentApplicative
7892
7993 -- XXX add merge tests like zip tests
8094 -- for mergeBy, we can split a list randomly into two lists and