@@ -14,7 +14,7 @@ import Data.Foldable (forM_, fold)
14import Data.List (sort)
14import Data.List (sort)
16import Data.IORef
16import Data.IORef
17−import Test.Hspec
17+import Test.Hspec as H
19import Streamly
19import Streamly
20import Streamly.Prelude ((.:), nil)
20import Streamly.Prelude ((.:), nil)
@@ -37,6 +37,76 @@ toListParallel = S.toList . wAsyncly
38main :: IO ()
38main :: IO ()
39main = hspec $ do
39main = hspec $ do
42+ describe "Nested parallel and serial compositions" $ do
47+ -- This is not correct, the result can also be [4,4,8,0,8,0,2,2]
48+ -- because of parallelism of [8,0] and [8,0].
49+ it "Nest <|>, <>, <|> (1)" $
52+ ((t 8 <|> t 4) <> (t 2 <|> t 0))
53+ <|> ((t 8 <|> t 4) <> (t 2 <|> t 0)))
54+ `shouldReturn` ([4,4,8,8,0,0,2,2])
56+ it "Nest <|>, <>, <|> (2)" $
57+ (S.toList . wAsyncly) (
58+ s (p (t 4 <> t 8) <> p (t 1 <> t 2))
59+ <> s (p (t 4 <> t 8) <> p (t 1 <> t 2)))
60+ `shouldReturn` ([4,4,8,8,1,1,2,2])
61+ -- FIXME: These two keep failing intermittently on Mac OS X
62+ -- Need to examine and fix the tests.
64+ it "Nest <|>, <=>, <|> (1)" $
67+ ((t 8 <|> t 4) <=> (t 2 <|> t 0))
68+ <|> ((t 9 <|> t 4) <=> (t 2 <|> t 0)))
69+ `shouldReturn` ([4,4,0,0,8,2,9,2])
70+ it "Nest <|>, <=>, <|> (2)" $
73+ ((t 4 <|> t 8) <=> (t 1 <|> t 2))
74+ <|> ((t 4 <|> t 9) <=> (t 1 <|> t 2)))
75+ `shouldReturn` ([4,4,1,1,8,2,9,2])
77+ it "Nest <|>, <|>, <|>" $
78+ (S.toList . wAsyncly) (
79+ ((t 4 <> t 8) <> (t 0 <> t 2))
80+ <> ((t 4 <> t 8) <> (t 0 <> t 2)))
81+ `shouldReturn` ([0,0,2,2,4,4,8,8])
83+ ---------------------------------------------------------------------------
84+ -- Semigroup/Monoidal Composition strict ordering checks
85+ ---------------------------------------------------------------------------
87+ -- test both (<>) and mappend to make sure we are using correct instance
88+ -- for Monoid that is using the right version of semigroup. Instance
89+ -- deriving can cause us to pick wrong instances sometimes.
91+ describe "WSerial interleaved (<>) ordering check" $ interleaveCheck wSerially (<>)
92+ describe "WSerial interleaved mappend ordering check" $ interleaveCheck wSerially mappend
94+ -- describe "WAsync interleaved (<>) ordering check" $ interleaveCheck wAsyncly (<>)
95+ -- describe "WAsync interleaved mappend ordering check" $ interleaveCheck wAsyncly mappend
97+ describe "Async (<>) time order check" $ parallelCheck asyncly (<>)
98+ describe "Async mappend time order check" $ parallelCheck asyncly mappend
100+ -- XXX this keeps failing intermittently, need to investigate
101+ -- describe "WAsync (<>) time order check" $ parallelCheck wAsyncly (<>)
102+ -- describe "WAsync mappend time order check" $ parallelCheck wAsyncly mappend
104+ describe "Parallel (<>) time order check" $ parallelCheck parallely (<>)
105+ describe "Parallel mappend time order check" $ parallelCheck parallely mappend
108+parallelTests :: SpecWith ()
109+parallelTests = H.parallel $ do
40 describe "Runners" $ do
110 describe "Runners" $ do
41 -- XXX move these to property tests
111 -- XXX move these to property tests
42 -- XXX use an IORef to store and check the side effects
112 -- XXX use an IORef to store and check the side effects
@@ -142,47 +212,6 @@ main = hspec $ do
142 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
212 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
145− describe "Nested parallel and serial compositions" $ do
150− -- This is not correct, the result can also be [4,4,8,0,8,0,2,2]
151− -- because of parallelism of [8,0] and [8,0].
152− it "Nest <|>, <>, <|> (1)" $
155− ((t 8 <|> t 4) <> (t 2 <|> t 0))
156− <|> ((t 8 <|> t 4) <> (t 2 <|> t 0)))
157− `shouldReturn` ([4,4,8,8,0,0,2,2])
159− it "Nest <|>, <>, <|> (2)" $
160− (S.toList . wAsyncly) (
161− s (p (t 4 <> t 8) <> p (t 1 <> t 2))
162− <> s (p (t 4 <> t 8) <> p (t 1 <> t 2)))
163− `shouldReturn` ([4,4,8,8,1,1,2,2])
164− -- FIXME: These two keep failing intermittently on Mac OS X
165− -- Need to examine and fix the tests.
167− it "Nest <|>, <=>, <|> (1)" $
170− ((t 8 <|> t 4) <=> (t 2 <|> t 0))
171− <|> ((t 9 <|> t 4) <=> (t 2 <|> t 0)))
172− `shouldReturn` ([4,4,0,0,8,2,9,2])
173− it "Nest <|>, <=>, <|> (2)" $
176− ((t 4 <|> t 8) <=> (t 1 <|> t 2))
177− <|> ((t 4 <|> t 9) <=> (t 1 <|> t 2)))
178− `shouldReturn` ([4,4,1,1,8,2,9,2])
180− it "Nest <|>, <|>, <|>" $
181− (S.toList . wAsyncly) (
182− ((t 4 <> t 8) <> (t 0 <> t 2))
183− <> ((t 4 <> t 8) <> (t 0 <> t 2)))
184− `shouldReturn` ([0,0,2,2,4,4,8,8])
186 ---------------------------------------------------------------------------
215 ---------------------------------------------------------------------------
187 -- Monoidal composition recursion loops
216 -- Monoidal composition recursion loops
188 ---------------------------------------------------------------------------
217 ---------------------------------------------------------------------------
@@ -387,30 +416,6 @@ main = hspec $ do
387 -- Slower tests are at the end
416 -- Slower tests are at the end
388 ---------------------------------------------------------------------------
417 ---------------------------------------------------------------------------
390− ---------------------------------------------------------------------------
391− -- Semigroup/Monoidal Composition strict ordering checks
392− ---------------------------------------------------------------------------
394− -- test both (<>) and mappend to make sure we are using correct instance
395− -- for Monoid that is using the right version of semigroup. Instance
396− -- deriving can cause us to pick wrong instances sometimes.
398− describe "WSerial interleaved (<>) ordering check" $ interleaveCheck wSerially (<>)
399− describe "WSerial interleaved mappend ordering check" $ interleaveCheck wSerially mappend
401− -- describe "WAsync interleaved (<>) ordering check" $ interleaveCheck wAsyncly (<>)
402− -- describe "WAsync interleaved mappend ordering check" $ interleaveCheck wAsyncly mappend
404− describe "Async (<>) time order check" $ parallelCheck asyncly (<>)
405− describe "Async mappend time order check" $ parallelCheck asyncly mappend
407− -- XXX this keeps failing intermittently, need to investigate
408− -- describe "WAsync (<>) time order check" $ parallelCheck wAsyncly (<>)
409− -- describe "WAsync mappend time order check" $ parallelCheck wAsyncly mappend
411− describe "Parallel (<>) time order check" $ parallelCheck parallely (<>)
412− describe "Parallel mappend time order check" $ parallelCheck parallely mappend
414 ---------------------------------------------------------------------------
419 ---------------------------------------------------------------------------
415 -- Thread limits
420 -- Thread limits
416 ---------------------------------------------------------------------------
421 ---------------------------------------------------------------------------