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