on 43dda21 help sign in
119 lines 4.9 kB history raw
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
10module Streamly.Test.Prelude.Parallel (main) where
12import Data.List (sort)
13import Test.Hspec.QuickCheck
14import Test.Hspec as H
16import Streamly.Prelude
17import qualified Streamly.Prelude as S
19import Streamly.Test.Prelude.Common
21moduleName :: String
22moduleName = "Prelude.Parallel"
24main :: IO ()
25main = hspec
26 $ H.parallel
27#ifdef COVERAGE_BUILD
28 $ modifyMaxSuccess (const 10)
29#endif
30 $ describe moduleName $ do
31 let
32#ifndef COVERAGE_BUILD
33 parallelCommonOps :: IsStream t => [(String, ParallelT m a -> t m a)]
34#endif
35 parallelCommonOps = []
36#ifndef COVERAGE_BUILD
37 <> [("rate AvgRate 0.00000001", fromParallel . avgRate 0.00000001)]
38 <> [("maxBuffer (-1)", fromParallel . maxBuffer (-1))]
39#endif
40 let parallelOps :: IsStream t
41 => ((ParallelT IO a -> t IO a) -> Spec) -> Spec
42 parallelOps spec = mapOps spec $ makeOps fromParallel <> parallelCommonOps
44 describe "Construction" $ do
45 parallelOps $ prop "parallely replicateM" . constructWithReplicateM
46 parallelOps $ prop "parallely cons" . constructWithCons S.cons
47-- parallelOps $ prop "parallely consM" . constructWithConsM S.consM sort
48 parallelOps $ prop "parallely (.:)" . constructWithCons (S..:)
49-- parallelOps $ prop "parallely (|:)" . constructWithConsM (S.|:) sort
51 describe "Functor operations" $ do
52 parallelOps $ functorOps S.fromFoldable "parallely" sortEq
53 parallelOps $ functorOps folded "parallely folded" sortEq
55 describe "Monoid operations" $ do
56 parallelOps $ monoidOps "parallely" mempty sortEq
58 describe "Parallel loops" $ loops fromParallel sort sort
60 describe "Bind and Monoidal composition combinations" $ do
61 -- XXX Taking a long time when parallelOps is used.
62 bindAndComposeSimpleOps "Parallel" sortEq fromParallel
63 bindAndComposeHierarchyOps "Parallel" fromParallel
64 parallelOps $ nestTwoStreams "Parallel" sort sort
65 parallelOps $ nestTwoStreamsApp "Parallel" sort sort
67 describe "Semigroup operations" $ do
68 parallelOps $ semigroupOps "parallely" sortEq
70 describe "Applicative operations" $ do
71 parallelOps $ applicativeOps folded "parallely applicative folded" sortEq
73 -- XXX add tests for indexed/indexedR
74 describe "Zip operations" $ do
75 -- We test only the serial zip with serial streams and the parallel
76 -- stream, because the rate setting in these streams can slow down
77 -- zipAsync.
78 parallelOps $ prop "zip monadic parallely" . zipMonadic S.fromFoldable (==)
79 parallelOps $ prop "zip monadic parallely folded" . zipMonadic folded (==)
81 -- XXX add merge tests like zip tests
82 -- for mergeBy, we can split a list randomly into two lists and
83 -- then merge them, it should result in original list
84 -- describe "Merge operations" $ do
86 describe "Monad operations" $ do
87 parallelOps $ prop "parallely monad then" . monadThen S.fromFoldable sortEq
88 parallelOps $ prop "parallely monad then folded" . monadThen folded sortEq
89 parallelOps $ prop "parallely monad bind" . monadBind S.fromFoldable sortEq
90 parallelOps $ prop "parallely monad bind folded" . monadBind folded sortEq
92 describe "Stream transform and combine operations" $ do
93 parallelOps $ transformCombineOpsCommon S.fromFoldable "parallely" sortEq
94 parallelOps $ transformCombineOpsCommon folded "parallely" sortEq
96 describe "Stream elimination operations" $ do
97 parallelOps $ eliminationOps S.fromFoldable "parallely"
98 parallelOps $ eliminationOps folded "parallely folded"
99 parallelOps $ eliminationOpsWord8 S.fromFoldable "parallely"
100 parallelOps $ eliminationOpsWord8 folded "parallely folded"
102 -- test both (<>) and mappend to make sure we are using correct instance
103 -- for Monoid that is using the right version of semigroup. Instance
104 -- deriving can cause us to pick wrong instances sometimes.
106#ifdef DEVBUILD
107 describe "Parallel (<>) time order check" $ parallelCheck fromParallel (<>)
108 describe "Parallel mappend time order check" $ parallelCheck fromParallel mappend
109#endif
111 describe "Tests for exceptions" $ parallelOps $ exceptionOps "parallely"
112 describe "Composed MonadThrow parallely" $ composeWithMonadThrow fromParallel
114#ifdef DEVBUILD
115 -- fromParallel fails on CI machines, may need more difference in times of
116 -- the events, but that would make tests even slower.
117 it "take 1 parallely" $ checkCleanup 3 fromParallel (S.take 1)
118 it "takeWhile (< 0) parallely" $ checkCleanup 3 fromParallel (S.takeWhile (< 0))
119#endif