on master help sign in
Refactor Parallel ops into a separate test suite.
commit0b79fce40017be3cea579583732d606ca2044bb7 authorPranay Sashank <pranaysashank@composewell.com> dateSat 25 Jul 2020, 05:52 (6 years ago) parent050b567
3 files changed+89−61
streamly.cabal+8 test/Prop.hs−61 test/Streamly/Test/Prelude/Parallel.hs+81
streamly.cabal+8
@@ -640,6 +640,14 @@ test-suite Prelude.WAsync
640640 other-modules: Streamly.Test.Common
641641 , Streamly.Test.Prelude
642642
643+test-suite Prelude.Parallel
644+ import: test-options, prelude-test-options
645+ type: exitcode-stdio-1.0
646+ main-is: Streamly/Test/Prelude/Parallel.hs
647+ ghc-options: -main-is Streamly.Test.Prelude.Parallel.main
648+ other-modules: Streamly.Test.Common
649+ , Streamly.Test.Prelude
650+
643651test-suite array-test
644652 import: test-options
645653 type: exitcode-stdio-1.0
test/Prop.hs−61
@@ -235,59 +235,12 @@ main = hspec
235235 <> [("rate AvgRate 0.00000001", parallely . avgRate 0.00000001)]
236236 <> [("maxBuffer (-1)", parallely . maxBuffer (-1))]
237237#endif
238− let parallelOps :: IsStream t
239− => ((ParallelT IO a -> t IO a) -> Spec) -> Spec
240− parallelOps spec = mapOps spec $ makeOps parallely <> parallelCommonOps
241238
242239 let parallelConcurrentAppOps :: IsStream t
243240 => ((ParallelT IO a -> t IO a) -> Spec) -> Spec
244241 parallelConcurrentAppOps spec =
245242 mapOps spec $ makeConcurrentAppOps parallely <> parallelCommonOps
246243
247− describe "Construction" $ do
248− parallelOps $ prop "parallely replicateM" . constructWithReplicateM
249−
250− -- take doesn't work well on concurrent streams. Even though it
251− -- seems like take only has a problem when used with parallely.
252− -- wSerialOps $ prop "wSerially iterateM" wSerially . constructWithIterate
253− -- aheadOps $ prop "aheadly iterateM" aheadly . onstructWithIterate
254− -- asyncOps $ prop "asyncly iterateM" asyncly . constructWithIterate
255− -- wAsyncOps $ prop "wAsyncly iterateM" wAsyncly . onstructWithIterate
256− -- parallelOps $ prop "parallely iterateM" parallely . onstructWithIterate
257− -- XXX add tests for fromIndices
258−
259− describe "Functor operations" $ do
260− parallelOps $ functorOps S.fromFoldable "parallely" sortEq
261− parallelOps $ functorOps folded "parallely folded" sortEq
262−
263− describe "Semigroup operations" $ do
264− parallelOps $ semigroupOps "parallely" sortEq
265−
266− describe "Applicative operations" $ do
267− parallelOps $ prop "parallely applicative folded" . applicativeOps folded sortEq
268−
269− -- XXX add tests for indexed/indexedR
270− describe "Zip operations" $ do
271− -- We test only the serial zip with serial streams and the parallel
272− -- stream, because the rate setting in these streams can slow down
273− -- zipAsync.
274− parallelOps $ prop "zip monadic parallely" . zipMonadic S.fromFoldable (==)
275− parallelOps $ prop "zip monadic parallely folded" . zipMonadic folded (==)
276−
277− -- XXX add merge tests like zip tests
278− -- for mergeBy, we can split a list randomly into two lists and
279− -- then merge them, it should result in original list
280− -- describe "Merge operations" $ do
281−
282− describe "Monad operations" $ do
283− parallelOps $ prop "parallely monad then" . monadThen S.fromFoldable sortEq
284−
285− parallelOps $ prop "parallely monad then folded" . monadThen folded sortEq
286−
287− parallelOps $ prop "parallely monad bind" . monadBind S.fromFoldable sortEq
288−
289− parallelOps $ prop "parallely monad bind folded" . monadBind folded sortEq
290−
291244 -- These tests won't work with maxBuffer or maxThreads set to 1, so we
292245 -- exclude those cases from these.
293246 let mkOps :: IsStream t => (t m a -> c) -> [(String, t m a -> c)]
@@ -324,17 +277,3 @@ main = hspec
324277 concurrentFoldrApplication
325278 prop "concurrent foldl application" $ withMaxSuccess maxTestCount
326279 concurrentFoldlApplication
327−
328− describe "Stream transform and combine operations" $ do
329− parallelOps $ transformCombineOpsCommon S.fromFoldable "parallely" sortEq
330−
331− parallelOps $ transformCombineOpsCommon folded "parallely" sortEq
332−
333− describe "Stream elimination operations" $ do
334− parallelOps $ eliminationOps S.fromFoldable "parallely"
335−
336− parallelOps $ eliminationOps folded "parallely folded"
337−
338− parallelOps $ eliminationOpsWord8 S.fromFoldable "parallely"
339−
340− parallelOps $ eliminationOpsWord8 folded "parallely folded"
test/Streamly/Test/Prelude/Parallel.hsnew file+81
@@ -0,0 +1,81 @@
1+-- |
2+-- Module : Streamly.Test.Prelude.Parallel
3+-- Copyright : (c) 2020 Composewell Technologies
4+--
5+-- License : BSD-3-Clause
6+-- Maintainer : streamly@composewell.com
7+-- Stability : experimental
8+-- Portability : GHC
9+
10+module Streamly.Test.Prelude.Parallel where
11+
12+#if __GLASGOW_HASKELL__ < 808
13+import Data.Semigroup ((<>))
14+#endif
15+import Test.Hspec.QuickCheck
16+import Test.Hspec as H
17+
18+import Streamly
19+import qualified Streamly.Prelude as S
20+
21+import Streamly.Test.Prelude
22+
23+main :: IO ()
24+main = hspec
25+ $ H.parallel
26+#ifdef COVERAGE_BUILD
27+ $ modifyMaxSuccess (const 10)
28+#endif
29+ $ do
30+ let parallelCommonOps :: IsStream t => [(String, ParallelT m a -> t m a)]
31+ parallelCommonOps = []
32+#ifndef COVERAGE_BUILD
33+ <> [("rate AvgRate 0.00000001", parallely . avgRate 0.00000001)]
34+ <> [("maxBuffer (-1)", parallely . maxBuffer (-1))]
35+#endif
36+ let parallelOps :: IsStream t
37+ => ((ParallelT IO a -> t IO a) -> Spec) -> Spec
38+ parallelOps spec = mapOps spec $ makeOps parallely <> parallelCommonOps
39+
40+ describe "Construction" $ do
41+ parallelOps $ prop "parallely replicateM" . constructWithReplicateM
42+
43+ describe "Functor operations" $ do
44+ parallelOps $ functorOps S.fromFoldable "parallely" sortEq
45+ parallelOps $ functorOps folded "parallely folded" sortEq
46+
47+ describe "Semigroup operations" $ do
48+ parallelOps $ semigroupOps "parallely" sortEq
49+
50+ describe "Applicative operations" $ do
51+ parallelOps $
52+ prop "parallely applicative folded" . applicativeOps folded sortEq
53+
54+ -- XXX add tests for indexed/indexedR
55+ describe "Zip operations" $ do
56+ -- We test only the serial zip with serial streams and the parallel
57+ -- stream, because the rate setting in these streams can slow down
58+ -- zipAsync.
59+ parallelOps $ prop "zip monadic parallely" . zipMonadic S.fromFoldable (==)
60+ parallelOps $ prop "zip monadic parallely folded" . zipMonadic folded (==)
61+
62+ -- XXX add merge tests like zip tests
63+ -- for mergeBy, we can split a list randomly into two lists and
64+ -- then merge them, it should result in original list
65+ -- describe "Merge operations" $ do
66+
67+ describe "Monad operations" $ do
68+ parallelOps $ prop "parallely monad then" . monadThen S.fromFoldable sortEq
69+ parallelOps $ prop "parallely monad then folded" . monadThen folded sortEq
70+ parallelOps $ prop "parallely monad bind" . monadBind S.fromFoldable sortEq
71+ parallelOps $ prop "parallely monad bind folded" . monadBind folded sortEq
72+
73+ describe "Stream transform and combine operations" $ do
74+ parallelOps $ transformCombineOpsCommon S.fromFoldable "parallely" sortEq
75+ parallelOps $ transformCombineOpsCommon folded "parallely" sortEq
76+
77+ describe "Stream elimination operations" $ do
78+ parallelOps $ eliminationOps S.fromFoldable "parallely"
79+ parallelOps $ eliminationOps folded "parallely folded"
80+ parallelOps $ eliminationOpsWord8 S.fromFoldable "parallely"
81+ parallelOps $ eliminationOpsWord8 folded "parallely folded"