on master help sign in
Fix test and benchmarks for concurrent module changes
dabe66cHarendra Kumar
benchmark/Streamly/Benchmark/Data/Stream/ConcurrentCommon.hs+1−1
@@ -68,7 +68,7 @@ o_n_heap_buffering value f =
68async2 :: (Config -> Config) -> Int -> Int -> IO ()
68async2 :: (Config -> Config) -> Int -> Int -> IO ()
69async2 f count n =
69async2 f count n =
70 Stream.fold Fold.drain
70 Stream.fold Fold.drain
71− $ Async.combineWith f
71+ $ Async.parTwo f
72 (sourceUnfoldrM count n) (sourceUnfoldrM count (n + 1))
72 (sourceUnfoldrM count n) (sourceUnfoldrM count (n + 1))
73
73
74{-# INLINE concatAsync2 #-}
74{-# INLINE concatAsync2 #-}
test/Streamly/Test/Data/Stream/Concurrent.hs+33−32
@@ -68,8 +68,8 @@ transformCombineFromList ::
68transformCombineFromList constr eq listOp op a b c =
68transformCombineFromList constr eq listOp op a b c =
69 withMaxSuccess maxTestCount $
69 withMaxSuccess maxTestCount $
70 monadicIO $ do
70 monadicIO $ do
71− let s1 = op (Async.parLazy [constr b, constr c])
71+ let s1 = op (Async.parList id [constr b, constr c])
72− let s2 = Async.parLazy [constr a, s1]
72+ let s2 = Async.parList id [constr a, s1]
73 stream <- run (Stream.fold Fold.toList s2)
73 stream <- run (Stream.fold Fold.toList s2)
74 let list = a <> listOp (b <> c)
74 let list = a <> listOp (b <> c)
75 listEquals eq stream list
75 listEquals eq stream list
@@ -140,15 +140,15 @@ exceptionPropagation f = do
140 :: Either ExampleException [Int])
140 :: Either ExampleException [Int])
141 it "sequence throwM" $
141 it "sequence throwM" $
142 let stream = Stream.fromList [throwM (ExampleException "E")]
142 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))
144 `shouldReturn`
144 `shouldReturn`
145 (Left (ExampleException "E") :: Either ExampleException [Int])
145 (Left (ExampleException "E") :: Either ExampleException [Int])
146
146
147 it "concatMap throwM" $ do
147 it "concatMap throwM" $ do
148− let s1 = Async.parConcatList id $ fmap Stream.fromPure [1..4]
148+ let s1 = Async.parList id $ fmap Stream.fromPure [1..4]
149− s2 = Async.parConcatList id $ fmap Stream.fromPure [5..8]
149+ s2 = Async.parList id $ fmap Stream.fromPure [5..8]
150 try $ tl (
150 try $ tl (
151− let bind = flip Async.concatMap
151+ let bind = flip (Async.parConcatMap id)
152 in bind s1 $ \x ->
152 in bind s1 $ \x ->
153 bind s2 $ \y ->
153 bind s2 $ \y ->
154 if x + y > 10
154 if x + y > 10
@@ -183,7 +183,7 @@ timeOrdering f = do
183takeCombined :: Int -> IO ()
183takeCombined :: Int -> IO ()
184takeCombined n = do
184takeCombined n = do
185 let constr = Stream.fromFoldable
185 let constr = Stream.fromFoldable
186− let s = Async.parLazy [constr ([] :: [Int]), constr ([] :: [Int])]
186+ let s = Async.parList id [constr ([] :: [Int]), constr ([] :: [Int])]
187 r <- Stream.fold Fold.toList $ Stream.take n s
187 r <- Stream.fold Fold.toList $ Stream.take n s
188 r `shouldBe` []
188 r `shouldBe` []
189
189
@@ -229,77 +229,78 @@ main = hspec
229 prop "eval" $
229 prop "eval" $
230 transform
230 transform
231 (fmap (+2))
231 (fmap (+2))
232− (fmap (+1) . Async.eval . fmap (+1))
232+ (fmap (+1) . Async.parEval id . fmap (+1))
233
233
234 asyncSpec $ prop "parSequence" . sequenceReplicate
234 asyncSpec $ prop "parSequence" . sequenceReplicate
235 -- XXX Need to use asyncSpec in all tests
235 -- XXX Need to use asyncSpec in all tests
236 prop "mapM (+1)" $
236 prop "mapM (+1)" $
237− transform (fmap (+1)) (Async.mapM (\x -> return (x + 1)))
237+ transform (fmap (+1)) (Async.parMapM id (\x -> return (x + 1)))
238
238
239 -- XXX Need to use eq instead of sortEq for ahead oeprations
239 -- XXX Need to use eq instead of sortEq for ahead oeprations
240 -- Binary append
240 -- Binary append
241 prop1 "append [] []"
241 prop1 "append [] []"
242− $ cmp (Async.parLazy [Stream.nil, Stream.nil]) sortEq []
242+ $ cmp (Async.parList id [Stream.nil, Stream.nil]) sortEq []
243 prop1 "append [] [1]"
243 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]
245 prop1 "append [1] []"
245 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]
247 prop1 "append [0] [1]"
247 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]
249 in cmp stream sortEq [0, 1]
249 in cmp stream sortEq [0, 1]
250
250
251 prop1 "append [0] [] [1]"
251 prop1 "append [0] [] [1]"
252 $ let stream =
252 $ let stream =
253− Async.parLazy
253+ Async.parList id
254 [Stream.fromPure 0, Stream.nil, Stream.fromPure 1]
254 [Stream.fromPure 0, Stream.nil, Stream.fromPure 1]
255 in cmp stream sortEq [0, 1]
255 in cmp stream sortEq [0, 1]
256
256
257+ let async = Async.parTwo id
257 prop1 "append2 left associated"
258 prop1 "append2 left associated"
258 $ let stream =
259 $ let stream =
259 Stream.fromPure 0
260 Stream.fromPure 0
260− `Async.append2` Stream.fromPure 1
261+ `async` Stream.fromPure 1
261− `Async.append2` Stream.fromPure 2
262+ `async` Stream.fromPure 2
262− `Async.append2` Stream.fromPure 3
263+ `async` Stream.fromPure 3
263 in cmp stream sortEq [0, 1, 2, 3]
264 in cmp stream sortEq [0, 1, 2, 3]
264
265
265 prop1 "append right associated"
266 prop1 "append right associated"
266 $ let stream =
267 $ let stream =
267 Stream.fromPure 0
268 Stream.fromPure 0
268− `Async.append2` (Stream.fromPure 1
269+ `async` (Stream.fromPure 1
269− `Async.append2` (Stream.fromPure 2
270+ `async` (Stream.fromPure 2
270− `Async.append2` Stream.fromPure 3))
271+ `async` Stream.fromPure 3))
271 in cmp stream sortEq [0, 1, 2, 3]
272 in cmp stream sortEq [0, 1, 2, 3]
272
273
273 prop1 "append balanced"
274 prop1 "append balanced"
274− $ let leaf x y = Stream.fromPure x `Async.append2` Stream.fromPure y
275+ $ let leaf x y = Stream.fromPure x `async` Stream.fromPure y
275− leaf11 = leaf 0 1 `Async.append2` leaf 2 (3 :: Int)
276+ leaf11 = leaf 0 1 `async` leaf 2 (3 :: Int)
276− leaf12 = leaf 4 5 `Async.append2` leaf 6 7
277+ leaf12 = leaf 4 5 `async` leaf 6 7
277− stream = leaf11 `Async.append2` leaf12
278+ stream = leaf11 `async` leaf12
278 in cmp stream sortEq [0, 1, 2, 3, 4, 5, 6,7]
279 in cmp stream sortEq [0, 1, 2, 3, 4, 5, 6,7]
279
280
280 prop1 "combineWith (maxThreads 1)"
281 prop1 "combineWith (maxThreads 1)"
281 $ let stream =
282 $ let stream =
282− Async.combineWith (Async.maxThreads 1)
283+ Async.parTwo (Async.maxThreads 1)
283 (Stream.fromList [1,2,3,4,5])
284 (Stream.fromList [1,2,3,4,5])
284 (Stream.fromList [6,7,8,9,10])
285 (Stream.fromList [6,7,8,9,10])
285 in cmp stream (==) [1,2,3,4,5,6,7,8,9,10]
286 in cmp stream (==) [1,2,3,4,5,6,7,8,9,10]
286
287
287 prop1 "apply (async arg1)"
288 prop1 "apply (async arg1)"
288− $ let s1 = Async.apply (Stream.fromPure (,)) (Stream.fromPure 1 `Async.append2` Stream.fromPure 2)
289+ $ let s1 = Async.parApply id (Stream.fromPure (,)) (Stream.fromPure 1 `async` Stream.fromPure 2)
289− s2 = Async.apply s1 (Stream.fromPure 3) :: Stream IO (Int, Int)
290+ s2 = Async.parApply id s1 (Stream.fromPure 3) :: Stream IO (Int, Int)
290 xs = Stream.fold Fold.toList s2
291 xs = Stream.fold Fold.toList s2
291 in sort <$> xs `shouldReturn` [(1, 3), (2, 3)]
292 in sort <$> xs `shouldReturn` [(1, 3), (2, 3)]
292
293
293 prop1 "apply (async arg2)"
294 prop1 "apply (async arg2)"
294 $ let s1 = Stream.fromPure (1,)
295 $ 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)
296 xs = Stream.fold Fold.toList s2 :: IO [(Int, Int)]
297 xs = Stream.fold Fold.toList s2 :: IO [(Int, Int)]
297 in sort <$> xs `shouldReturn` [(1, 2), (1, 3)]
298 in sort <$> xs `shouldReturn` [(1, 2), (1, 3)]
298
299
299 -- concat
300 -- concat
300 prop1 "concat"
301 prop1 "concat"
301 $ let stream =
302 $ let stream =
302− Async.concat
303+ Async.parConcat id
303 $ fmap Stream.fromPure
304 $ fmap Stream.fromPure
304 $ Stream.fromList [1..100]
305 $ Stream.fromList [1..100]
305 in cmp stream sortEq [1..100]
306 in cmp stream sortEq [1..100]
@@ -308,11 +309,11 @@ main = hspec
308 forAll (choose (0, 100)) $ \n ->
309 forAll (choose (0, 100)) $ \n ->
309 transform
310 transform
310 (concatMap (const [1..n]))
311 (concatMap (const [1..n]))
311− (Async.concatMap (const (Stream.fromList [1..n])))
312+ (Async.parConcatMap id (const (Stream.fromList [1..n])))
312
313
313#ifdef DEVBUILD
314#ifdef DEVBUILD
314− describe "Time ordering" $ timeOrdering Async.parLazy
315+ describe "Time ordering" $ timeOrdering Async.parList id
315#endif
316#endif
316− describe "Exception propagation" $ exceptionPropagation Async.append2
317+ describe "Exception propagation" $ exceptionPropagation async
317 -- Ad-hoc tests
318 -- Ad-hoc tests
318 it "takes n from stream of streams" $ takeCombined 2
319 it "takes n from stream of streams" $ takeCombined 2
test/Streamly/Test/Prelude/Serial.hs+1−1
@@ -497,7 +497,7 @@ testFromCallback :: IO Int
497testFromCallback = do
497testFromCallback = do
498 ref <- newIORef Nothing
498 ref <- newIORef Nothing
499 let stream =
499 let stream =
500− S.parConcatList (S.eager True)
500+ S.parList (S.eager True)
501 [ fmap Just (S.fromCallback (setCallback ref))
501 [ fmap Just (S.fromCallback (setCallback ref))
502 , runCallback ref
502 , runCallback ref
503 ]
503 ]