on master help sign in
Refactor Concurrent ops into a separate test suite.
commit0f773225efedf260f859c205576ad1e850b7b6db authorPranay Sashank <pranaysashank@composewell.com> dateSat 25 Jul 2020, 06:07 (6 years ago) parent0b79fce
2 files changed+46−14
streamly.cabal+8−7 test/Prop.hs → test/Streamly/Test/Prelude/Concurrent.hs+38−7
streamly.cabal+8−7
@@ -577,13 +577,6 @@ test-suite pure-streams-streamly
577577 , hspec >= 2.0 && < 3
578578 default-language: Haskell2010
579579
580−test-suite properties
581− import: test-options, prelude-test-options
582− type: exitcode-stdio-1.0
583− main-is: Prop.hs
584− other-modules: Streamly.Test.Common
585− , Streamly.Test.Prelude
586−
587580test-suite Prelude.Serial
588581 import: test-options, prelude-test-options
589582 type: exitcode-stdio-1.0
@@ -648,6 +641,14 @@ test-suite Prelude.Parallel
648641 other-modules: Streamly.Test.Common
649642 , Streamly.Test.Prelude
650643
644+test-suite Prelude.Concurrent
645+ import: test-options, prelude-test-options
646+ type: exitcode-stdio-1.0
647+ main-is: Streamly/Test/Prelude/Concurrent.hs
648+ ghc-options: -main-is Streamly.Test.Prelude.Concurrent.main
649+ other-modules: Streamly.Test.Common
650+ , Streamly.Test.Prelude
651+
651652test-suite array-test
652653 import: test-options
653654 type: exitcode-stdio-1.0
test/Prop.hs → test/Streamly/Test/Prelude/Concurrent.hsrenamed+38−7
@@ -1,6 +1,15 @@
1+-- |
2+-- Module : Streamly.Test.Prelude.Concurrent
3+-- Copyright : (c) 2020 Composewell Technologies
4+--
5+-- License : BSD-3-Clause
6+-- Maintainer : streamly@composewell.com
7+-- Stability : experimental
8+-- Portability : GHC
9+
110{-# LANGUAGE OverloadedLists #-}
211
3−module Main (main) where
12+module Streamly.Test.Prelude.Concurrent where
413
514import Control.Concurrent (MVar, takeMVar, putMVar, newEmptyMVar)
615import Control.Exception
@@ -8,15 +17,16 @@ import Control.Exception
817 BlockedIndefinitelyOnSTM(..), Handler(..))
918import Control.Monad (when, forM_, replicateM_)
1019import Data.IORef (readIORef, modifyIORef, newIORef)
20+#if __GLASGOW_HASKELL__ < 808
21+import Data.Semigroup ((<>))
22+#endif
1123import GHC.Word (Word8)
12−
1324import Test.Hspec.QuickCheck
25+import Test.Hspec as H
1426import Test.QuickCheck
1527 (Property, withMaxSuccess)
1628import Test.QuickCheck.Monadic (monadicIO, run)
1729
18−import Test.Hspec as H
19−
2030import Streamly
2131import qualified Streamly.Prelude as S
2232
@@ -218,6 +228,26 @@ main = hspec
218228 $ modifyMaxSuccess (const 10)
219229#endif
220230 $ do
231+ -- We can have these in Test.Prelude, but I think it's unnecessary.
232+ let serialOps :: IsStream t => ((SerialT IO a -> t IO a) -> Spec) -> Spec
233+ serialOps spec = mapOps spec $ makeOps serially
234+#ifndef COVERAGE_BUILD
235+ <> [("rate AvgRate 0.00000001", serially . avgRate 0.00000001)]
236+ <> [("maxBuffer -1", serially . maxBuffer (-1))]
237+#endif
238+
239+ let aheadOps :: IsStream t => ((AheadT IO a -> t IO a) -> Spec) -> Spec
240+ aheadOps spec = mapOps spec $ makeOps aheadly
241+#ifndef COVERAGE_BUILD
242+ <> [("maxBuffer (-1)", aheadly . maxBuffer (-1))]
243+#endif
244+
245+ let asyncOps :: IsStream t => ((AsyncT IO a -> t IO a) -> Spec) -> Spec
246+ asyncOps spec = mapOps spec $ makeOps asyncly
247+#ifndef COVERAGE_BUILD
248+ <> [("maxBuffer (-1)", asyncly . maxBuffer (-1))]
249+#endif
250+
221251 -- For concurrent application test we need a buffer of at least size 2 to
222252 -- allow two threads to run.
223253 let makeConcurrentAppOps :: IsStream t
@@ -267,9 +297,10 @@ main = hspec
267297 forOps (mkOps parallely) $ concurrentOps folded "parallely folded" sortEq
268298
269299 describe "Concurrent application" $ do
270−-- serialOps $ prop "serial" . concurrentApplication (==)
271−-- asyncOps $ prop "async" . concurrentApplication sortEq
272−-- aheadOps $ prop "ahead" . concurrentApplication (==)
300+ serialOps $ prop "serial" . concurrentApplication (==)
301+ asyncOps $ prop "async" . concurrentApplication sortEq
302+ aheadOps $ prop "ahead" . concurrentApplication (==)
303+
273304 parallelConcurrentAppOps $
274305 prop "parallel" . concurrentApplication sortEq
275306