@@ -13,12 +13,13 @@ module Streamly.Test.Prelude.Fold where
13import Control.Concurrent (threadDelay)
13import Control.Concurrent (threadDelay)
15import Control.Exception (ErrorCall(..), catch)
15import Control.Exception (ErrorCall(..), catch)
16−import Data.IORef ( newIORef, readIORef, writeIORef, IORef )
16+import Data.IORef (newIORef, readIORef, writeIORef, IORef)
17#ifdef COVERAGE_BUILD
17#ifdef COVERAGE_BUILD
18import Test.Hspec.QuickCheck (modifyMaxSuccess)
18import Test.Hspec.QuickCheck (modifyMaxSuccess)
20import Test.Hspec as H
20import Test.Hspec as H
21#ifdef DEVBUILD
21#ifdef DEVBUILD
22+import Data.IORef (modifyIORef)
22import System.Mem (performMajorGC)
23import System.Mem (performMajorGC)
@@ -63,14 +64,20 @@ checkCleanupFold :: IsStream t
63 -> (SerialT IO Int -> IO (Maybe Int))
64 -> (SerialT IO Int -> IO (Maybe Int))
65checkCleanupFold t op = do
66checkCleanupFold t op = do
66− r <- newIORef (-1 :: Int)
67+ r <- newIORef ([] :: [Int])
67 _ <- op $ t $ delay r 0 S.|: delay r 2 S.|: delay r 3 S.|: S.nil
68 _ <- op $ t $ delay r 0 S.|: delay r 2 S.|: delay r 3 S.|: S.nil
68 performMajorGC
69 performMajorGC
70+ -- In case the actions are not killed let them fire before we check so that
69− threadDelay 700000
72+ threadDelay (4 * delayUnit)
70 res <- readIORef r
73 res <- readIORef r
71− res `shouldBe` 0
74+ res `shouldBe` [0]
73− delay ref i = threadDelay (i*200000) >> writeIORef ref i >> return i
80+ threadDelay (i * delayUnit) >> modifyIORef ref (i :) >> return i
75testFoldOpsCleanup :: String -> (SerialT IO Int -> IO a) -> Spec
82testFoldOpsCleanup :: String -> (SerialT IO Int -> IO a) -> Spec
76testFoldOpsCleanup name f = do
83testFoldOpsCleanup name f = do