on master help sign in
Use streamly clock instead of "clock" pkg
2c0f829Harendra Kumar
streamly.cabal−1
@@ -613,7 +613,6 @@ test-suite maxrate
613 build-Depends:
613 build-Depends:
614 streamly
614 streamly
615 , base >= 4.8 && < 5
615 , base >= 4.8 && < 5
616− , clock >= 0.7.1 && < 0.9
617 , hspec >= 2.0 && < 3
616 , hspec >= 2.0 && < 3
618 , random >= 1.0.0 && < 2
617 , random >= 1.0.0 && < 2
619 else
618 else
test/MaxRate.hs+8−6
@@ -3,20 +3,22 @@
3
3
4import Streamly
4import Streamly
5import qualified Streamly.Prelude as S
5import qualified Streamly.Prelude as S
6+import Streamly.Internal.Data.Time.Clock (getTime, Clock(..))
7+import Streamly.Internal.Data.Time.Units
8+ (NanoSecond64, diffAbsTime64, fromRelTime64)
9+
6import Control.Concurrent
10import Control.Concurrent
7import Control.Monad
11import Control.Monad
8−import System.Clock
9−import Test.Hspec
10import System.Random
12import System.Random
13+import Test.Hspec
11
14
12durationShouldBe :: (Double, Double) -> IO () -> Expectation
15durationShouldBe :: (Double, Double) -> IO () -> Expectation
13durationShouldBe d@(tMin, tMax) action = do
16durationShouldBe d@(tMin, tMax) action = do
14 t0 <- getTime Monotonic
17 t0 <- getTime Monotonic
15 action
18 action
16 t1 <- getTime Monotonic
19 t1 <- getTime Monotonic
17− let t = fromIntegral (toNanoSecs (t1 - t0)) / 1e9
20+ let diff = fromRelTime64 (diffAbsTime64 t1 t0) :: NanoSecond64
18− -- tMax = fromNanoSecs (round $ d*10^9*1.2)
21+ let t = fromIntegral diff / 1e9
19− -- tMin = fromNanoSecs (round $ d*10^9*0.8)
20 putStrLn $ "Expected: " <> show d <> " Took: " <> show t
22 putStrLn $ "Expected: " <> show d <> " Took: " <> show t
21 (t <= tMax && t >= tMin) `shouldBe` True
23 (t <= tMax && t >= tMin) `shouldBe` True
22
24
@@ -50,7 +52,7 @@ measureRate' desc t buffers threads rval consumerDelay producerDelay expectedRan
50 <> ", consumer latency: " <> show consumerDelay
52 <> ", consumer latency: " <> show consumerDelay
51 <> ", producer latency: " <> show producerDelay)
53 <> ", producer latency: " <> show producerDelay)
52 $ durationShouldBe expectedRange $
54 $ durationShouldBe expectedRange $
53− runStream
55+ S.drain
54 $ (if consumerDelay > 0
56 $ (if consumerDelay > 0
55 then S.mapM $ \x ->
57 then S.mapM $ \x ->
56 threadDelay (toMicroSecs consumerDelay) >> return x
58 threadDelay (toMicroSecs consumerDelay) >> return x