@@ -1,6 +1,15 @@
2+-- Module : Streamly.Test.Prelude.Concurrent
3+-- Copyright : (c) 2020 Composewell Technologies
5+-- License : BSD-3-Clause
6+-- Maintainer : streamly@composewell.com
7+-- Stability : experimental
1{-# LANGUAGE OverloadedLists #-}
10{-# LANGUAGE OverloadedLists #-}
3−module Main (main) where
12+module Streamly.Test.Prelude.Concurrent where
5import Control.Concurrent (MVar, takeMVar, putMVar, newEmptyMVar)
14import Control.Concurrent (MVar, takeMVar, putMVar, newEmptyMVar)
6import Control.Exception
15import Control.Exception
@@ -8,15 +17,16 @@ import Control.Exception
8 BlockedIndefinitelyOnSTM(..), Handler(..))
17 BlockedIndefinitelyOnSTM(..), Handler(..))
9import Control.Monad (when, forM_, replicateM_)
18import Control.Monad (when, forM_, replicateM_)
10import Data.IORef (readIORef, modifyIORef, newIORef)
19import Data.IORef (readIORef, modifyIORef, newIORef)
20+#if __GLASGOW_HASKELL__ < 808
21+import Data.Semigroup ((<>))
11import GHC.Word (Word8)
23import GHC.Word (Word8)
13import Test.Hspec.QuickCheck
24import Test.Hspec.QuickCheck
25+import Test.Hspec as H
14import Test.QuickCheck
26import Test.QuickCheck
15 (Property, withMaxSuccess)
27 (Property, withMaxSuccess)
16import Test.QuickCheck.Monadic (monadicIO, run)
28import Test.QuickCheck.Monadic (monadicIO, run)
18−import Test.Hspec as H
20import Streamly
30import Streamly
21import qualified Streamly.Prelude as S
31import qualified Streamly.Prelude as S
@@ -218,6 +228,26 @@ main = hspec
218 $ modifyMaxSuccess (const 10)
228 $ modifyMaxSuccess (const 10)
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))]
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))]
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))]
221 -- For concurrent application test we need a buffer of at least size 2 to
251 -- For concurrent application test we need a buffer of at least size 2 to
222 -- allow two threads to run.
252 -- allow two threads to run.
223 let makeConcurrentAppOps :: IsStream t
253 let makeConcurrentAppOps :: IsStream t
@@ -267,9 +297,10 @@ main = hspec
267 forOps (mkOps parallely) $ concurrentOps folded "parallely folded" sortEq
297 forOps (mkOps parallely) $ concurrentOps folded "parallely folded" sortEq
269 describe "Concurrent application" $ do
299 describe "Concurrent application" $ do
270−-- serialOps $ prop "serial" . concurrentApplication (==)
300+ serialOps $ prop "serial" . concurrentApplication (==)
271−-- asyncOps $ prop "async" . concurrentApplication sortEq
301+ asyncOps $ prop "async" . concurrentApplication sortEq
272−-- aheadOps $ prop "ahead" . concurrentApplication (==)
302+ aheadOps $ prop "ahead" . concurrentApplication (==)
273 parallelConcurrentAppOps $
304 parallelConcurrentAppOps $
274 prop "parallel" . concurrentApplication sortEq
305 prop "parallel" . concurrentApplication sortEq