on master help sign in
Fix test and benchmarks for concurrent module changes
commitdabe66ceaa8314f901a0e54c29089b96f0d99b9e authorHarendra Kumar <harendra@composewell.com> dateFri 13 Jan 2023, 15:43 (4 years ago) parent9b0ce5c
3 files changed+35−34
benchmark/Streamly/Benchmark/Data/Stream/ConcurrentCommon.hs+1−1 test/Streamly/Test/Data/Stream/Concurrent.hs+33−32 test/Streamly/Test/Prelude/Serial.hs+1−1
benchmark/Streamly/Benchmark/Data/Stream/ConcurrentCommon.hs+1−1
@@ -68,7 +68,7 @@ o_n_heap_buffering value f =
6868async2 :: (Config -> Config) -> Int -> Int -> IO ()
6969async2 f count n =
7070 Stream.fold Fold.drain
71− $ Async.combineWith f
71+ $ Async.parTwo f
7272 (sourceUnfoldrM count n) (sourceUnfoldrM count (n + 1))
7373
7474{-# INLINE concatAsync2 #-}
test/Streamly/Test/Data/Stream/Concurrent.hs+33−32
@@ -68,8 +68,8 @@ transformCombineFromList ::
6868transformCombineFromList constr eq listOp op a b c =
6969 withMaxSuccess maxTestCount $
7070 monadicIO $ do
71− let s1 = op (Async.parLazy [constr b, constr c])
72− let s2 = Async.parLazy [constr a, s1]
71+ let s1 = op (Async.parList id [constr b, constr c])
72+ let s2 = Async.parList id [constr a, s1]
7373 stream <- run (Stream.fold Fold.toList s2)
7474 let list = a <> listOp (b <> c)
7575 listEquals eq stream list
@@ -140,15 +140,15 @@ exceptionPropagation f = do
140140 :: Either ExampleException [Int])
141141 it "sequence throwM" $
142142 let stream = Stream.fromList [throwM (ExampleException "E")]
143− in try (tl (Stream.nil `f` Async.sequence stream))
143+ in try (tl (Stream.nil `f` Async.parSequence id stream))
144144 `shouldReturn`
145145 (Left (ExampleException "E") :: Either ExampleException [Int])
146146
147147 it "concatMap throwM" $ do
148− let s1 = Async.parConcatList id $ fmap Stream.fromPure [1..4]
149− s2 = Async.parConcatList id $ fmap Stream.fromPure [5..8]
148+ let s1 = Async.parList id $ fmap Stream.fromPure [1..4]
149+ s2 = Async.parList id $ fmap Stream.fromPure [5..8]
150150 try $ tl (
151− let bind = flip Async.concatMap
151+ let bind = flip (Async.parConcatMap id)
152152 in bind s1 $ \x ->
153153 bind s2 $ \y ->
154154 if x + y > 10
@@ -183,7 +183,7 @@ timeOrdering f = do
183183takeCombined :: Int -> IO ()
184184takeCombined n = do
185185 let constr = Stream.fromFoldable
186− let s = Async.parLazy [constr ([] :: [Int]), constr ([] :: [Int])]
186+ let s = Async.parList id [constr ([] :: [Int]), constr ([] :: [Int])]
187187 r <- Stream.fold Fold.toList $ Stream.take n s
188188 r `shouldBe` []
189189
@@ -229,77 +229,78 @@ main = hspec
229229 prop "eval" $
230230 transform
231231 (fmap (+2))
232− (fmap (+1) . Async.eval . fmap (+1))
232+ (fmap (+1) . Async.parEval id . fmap (+1))
233233
234234 asyncSpec $ prop "parSequence" . sequenceReplicate
235235 -- XXX Need to use asyncSpec in all tests
236236 prop "mapM (+1)" $
237− transform (fmap (+1)) (Async.mapM (\x -> return (x + 1)))
237+ transform (fmap (+1)) (Async.parMapM id (\x -> return (x + 1)))
238238
239239 -- XXX Need to use eq instead of sortEq for ahead oeprations
240240 -- Binary append
241241 prop1 "append [] []"
242− $ cmp (Async.parLazy [Stream.nil, Stream.nil]) sortEq []
242+ $ cmp (Async.parList id [Stream.nil, Stream.nil]) sortEq []
243243 prop1 "append [] [1]"
244− $ cmp (Async.parLazy [Stream.nil, Stream.fromPure 1]) sortEq [1]
244+ $ cmp (Async.parList id [Stream.nil, Stream.fromPure 1]) sortEq [1]
245245 prop1 "append [1] []"
246− $ cmp (Async.parLazy [Stream.fromPure 1, Stream.nil]) sortEq [1]
246+ $ cmp (Async.parList id [Stream.fromPure 1, Stream.nil]) sortEq [1]
247247 prop1 "append [0] [1]"
248− $ let stream = Async.parLazy [Stream.fromPure 0, Stream.fromPure 1]
248+ $ let stream = Async.parList id [Stream.fromPure 0, Stream.fromPure 1]
249249 in cmp stream sortEq [0, 1]
250250
251251 prop1 "append [0] [] [1]"
252252 $ let stream =
253− Async.parLazy
253+ Async.parList id
254254 [Stream.fromPure 0, Stream.nil, Stream.fromPure 1]
255255 in cmp stream sortEq [0, 1]
256256
257+ let async = Async.parTwo id
257258 prop1 "append2 left associated"
258259 $ let stream =
259260 Stream.fromPure 0
260− `Async.append2` Stream.fromPure 1
261− `Async.append2` Stream.fromPure 2
262− `Async.append2` Stream.fromPure 3
261+ `async` Stream.fromPure 1
262+ `async` Stream.fromPure 2
263+ `async` Stream.fromPure 3
263264 in cmp stream sortEq [0, 1, 2, 3]
264265
265266 prop1 "append right associated"
266267 $ let stream =
267268 Stream.fromPure 0
268− `Async.append2` (Stream.fromPure 1
269− `Async.append2` (Stream.fromPure 2
270− `Async.append2` Stream.fromPure 3))
269+ `async` (Stream.fromPure 1
270+ `async` (Stream.fromPure 2
271+ `async` Stream.fromPure 3))
271272 in cmp stream sortEq [0, 1, 2, 3]
272273
273274 prop1 "append balanced"
274− $ let leaf x y = Stream.fromPure x `Async.append2` Stream.fromPure y
275− leaf11 = leaf 0 1 `Async.append2` leaf 2 (3 :: Int)
276− leaf12 = leaf 4 5 `Async.append2` leaf 6 7
277− stream = leaf11 `Async.append2` leaf12
275+ $ let leaf x y = Stream.fromPure x `async` Stream.fromPure y
276+ leaf11 = leaf 0 1 `async` leaf 2 (3 :: Int)
277+ leaf12 = leaf 4 5 `async` leaf 6 7
278+ stream = leaf11 `async` leaf12
278279 in cmp stream sortEq [0, 1, 2, 3, 4, 5, 6,7]
279280
280281 prop1 "combineWith (maxThreads 1)"
281282 $ let stream =
282− Async.combineWith (Async.maxThreads 1)
283+ Async.parTwo (Async.maxThreads 1)
283284 (Stream.fromList [1,2,3,4,5])
284285 (Stream.fromList [6,7,8,9,10])
285286 in cmp stream (==) [1,2,3,4,5,6,7,8,9,10]
286287
287288 prop1 "apply (async arg1)"
288− $ let s1 = Async.apply (Stream.fromPure (,)) (Stream.fromPure 1 `Async.append2` Stream.fromPure 2)
289− s2 = Async.apply s1 (Stream.fromPure 3) :: Stream IO (Int, Int)
289+ $ let s1 = Async.parApply id (Stream.fromPure (,)) (Stream.fromPure 1 `async` Stream.fromPure 2)
290+ s2 = Async.parApply id s1 (Stream.fromPure 3) :: Stream IO (Int, Int)
290291 xs = Stream.fold Fold.toList s2
291292 in sort <$> xs `shouldReturn` [(1, 3), (2, 3)]
292293
293294 prop1 "apply (async arg2)"
294295 $ let s1 = Stream.fromPure (1,)
295− s2 = Async.apply s1 (Stream.fromPure 2 `Async.append2` Stream.fromPure 3)
296+ s2 = Async.parApply id s1 (Stream.fromPure 2 `async` Stream.fromPure 3)
296297 xs = Stream.fold Fold.toList s2 :: IO [(Int, Int)]
297298 in sort <$> xs `shouldReturn` [(1, 2), (1, 3)]
298299
299300 -- concat
300301 prop1 "concat"
301302 $ let stream =
302− Async.concat
303+ Async.parConcat id
303304 $ fmap Stream.fromPure
304305 $ Stream.fromList [1..100]
305306 in cmp stream sortEq [1..100]
@@ -308,11 +309,11 @@ main = hspec
308309 forAll (choose (0, 100)) $ \n ->
309310 transform
310311 (concatMap (const [1..n]))
311− (Async.concatMap (const (Stream.fromList [1..n])))
312+ (Async.parConcatMap id (const (Stream.fromList [1..n])))
312313
313314#ifdef DEVBUILD
314− describe "Time ordering" $ timeOrdering Async.parLazy
315+ describe "Time ordering" $ timeOrdering Async.parList id
315316#endif
316− describe "Exception propagation" $ exceptionPropagation Async.append2
317+ describe "Exception propagation" $ exceptionPropagation async
317318 -- Ad-hoc tests
318319 it "takes n from stream of streams" $ takeCombined 2
test/Streamly/Test/Prelude/Serial.hs+1−1
@@ -497,7 +497,7 @@ testFromCallback :: IO Int
497497testFromCallback = do
498498 ref <- newIORef Nothing
499499 let stream =
500− S.parConcatList (S.eager True)
500+ S.parList (S.eager True)
501501 [ fmap Just (S.fromCallback (setCallback ref))
502502 , runCallback ref
503503 ]