2-- Module : Streamly.Test.Prelude.Parallel
3-- Copyright : (c) 2020 Composewell Technologies
5-- License : BSD-3-Clause
6-- Maintainer : streamly@composewell.com
7-- Stability : experimental
10module Streamly.Test.Prelude.Parallel where
12import Data.List (sort)
13#if !(MIN_VERSION_base(4,11,0))
14import Data.Semigroup ((<>))
16import Test.Hspec.QuickCheck
19import Streamly.Prelude
20import qualified Streamly.Prelude as S
22import Streamly.Test.Prelude.Common
25moduleName = "Prelude.Parallel"
31 $ modifyMaxSuccess (const 10)
33 $ describe moduleName $ do
36 parallelCommonOps :: IsStream t => [(String, ParallelT m a -> t m a)]
38 parallelCommonOps = []
40 <> [("rate AvgRate 0.00000001", fromParallel . avgRate 0.00000001)]
41 <> [("maxBuffer (-1)", fromParallel . maxBuffer (-1))]
43 let parallelOps :: IsStream t
44 => ((ParallelT IO a -> t IO a) -> Spec) -> Spec
45 parallelOps spec = mapOps spec $ makeOps fromParallel <> parallelCommonOps
47 describe "Construction" $ do
48 parallelOps $ prop "parallely replicateM" . constructWithReplicateM
49 parallelOps $ prop "parallely cons" . constructWithCons S.cons
50-- parallelOps $ prop "parallely consM" . constructWithConsM S.consM sort
51 parallelOps $ prop "parallely (.:)" . constructWithCons (S..:)
52-- parallelOps $ prop "parallely (|:)" . constructWithConsM (S.|:) sort
54 describe "Functor operations" $ do
55 parallelOps $ functorOps S.fromFoldable "parallely" sortEq
56 parallelOps $ functorOps folded "parallely folded" sortEq
58 describe "Monoid operations" $ do
59 parallelOps $ monoidOps "parallely" mempty sortEq
61 describe "Parallel loops" $ loops fromParallel sort sort
63 describe "Bind and Monoidal composition combinations" $ do
64 -- XXX Taking a long time when parallelOps is used.
65 bindAndComposeSimpleOps "Parallel" sortEq fromParallel
66 bindAndComposeHierarchyOps "Parallel" fromParallel
67 parallelOps $ nestTwoStreams "Parallel" sort sort
68 parallelOps $ nestTwoStreamsApp "Parallel" sort sort
70 describe "Semigroup operations" $ do
71 parallelOps $ semigroupOps "parallely" sortEq
73 describe "Applicative operations" $ do
74 parallelOps $ applicativeOps folded "parallely applicative folded" sortEq
76 -- XXX add tests for indexed/indexedR
77 describe "Zip operations" $ do
78 -- We test only the serial zip with serial streams and the parallel
79 -- stream, because the rate setting in these streams can slow down
81 parallelOps $ prop "zip monadic parallely" . zipMonadic S.fromFoldable (==)
82 parallelOps $ prop "zip monadic parallely folded" . zipMonadic folded (==)
84 -- XXX add merge tests like zip tests
85 -- for mergeBy, we can split a list randomly into two lists and
86 -- then merge them, it should result in original list
87 -- describe "Merge operations" $ do
89 describe "Monad operations" $ do
90 parallelOps $ prop "parallely monad then" . monadThen S.fromFoldable sortEq
91 parallelOps $ prop "parallely monad then folded" . monadThen folded sortEq
92 parallelOps $ prop "parallely monad bind" . monadBind S.fromFoldable sortEq
93 parallelOps $ prop "parallely monad bind folded" . monadBind folded sortEq
95 describe "Stream transform and combine operations" $ do
96 parallelOps $ transformCombineOpsCommon S.fromFoldable "parallely" sortEq
97 parallelOps $ transformCombineOpsCommon folded "parallely" sortEq
99 describe "Stream elimination operations" $ do
100 parallelOps $ eliminationOps S.fromFoldable "parallely"
101 parallelOps $ eliminationOps folded "parallely folded"
102 parallelOps $ eliminationOpsWord8 S.fromFoldable "parallely"
103 parallelOps $ eliminationOpsWord8 folded "parallely folded"
105 -- test both (<>) and mappend to make sure we are using correct instance
106 -- for Monoid that is using the right version of semigroup. Instance
107 -- deriving can cause us to pick wrong instances sometimes.
110 describe "Parallel (<>) time order check" $ parallelCheck fromParallel (<>)
111 describe "Parallel mappend time order check" $ parallelCheck fromParallel mappend
114 describe "Tests for exceptions" $ parallelOps $ exceptionOps "parallely"
115 describe "Composed MonadThrow parallely" $ composeWithMonadThrow fromParallel
118 -- fromParallel fails on CI machines, may need more difference in times of
119 -- the events, but that would make tests even slower.
120 it "take 1 parallely" $ checkCleanup 3 fromParallel (S.take 1)
121 it "takeWhile (< 0) parallely" $ checkCleanup 3 fromParallel (S.takeWhile (< 0))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list