on master help sign in
Use streamly clock instead of "clock" pkg
commit2c0f829e353119037636ed647f1db3835ae231d5 authorHarendra Kumar <harendra@composewell.com> dateWed 3 Jun 2020, 20:13 (6 years ago) parent1691aa3
2 files changed+8−7
streamly.cabal−1 test/MaxRate.hs+8−6
streamly.cabal−1
@@ -613,7 +613,6 @@ test-suite maxrate
613613 build-Depends:
614614 streamly
615615 , base >= 4.8 && < 5
616− , clock >= 0.7.1 && < 0.9
617616 , hspec >= 2.0 && < 3
618617 , random >= 1.0.0 && < 2
619618 else
test/MaxRate.hs+8−6
@@ -3,20 +3,22 @@
33
44import Streamly
55import 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+
610import Control.Concurrent
711import Control.Monad
8−import System.Clock
9−import Test.Hspec
1012import System.Random
13+import Test.Hspec
1114
1215durationShouldBe :: (Double, Double) -> IO () -> Expectation
1316durationShouldBe d@(tMin, tMax) action = do
1417 t0 <- getTime Monotonic
1518 action
1619 t1 <- getTime Monotonic
17− let t = fromIntegral (toNanoSecs (t1 - t0)) / 1e9
18− -- tMax = fromNanoSecs (round $ d*10^9*1.2)
19− -- tMin = fromNanoSecs (round $ d*10^9*0.8)
20+ let diff = fromRelTime64 (diffAbsTime64 t1 t0) :: NanoSecond64
21+ let t = fromIntegral diff / 1e9
2022 putStrLn $ "Expected: " <> show d <> " Took: " <> show t
2123 (t <= tMax && t >= tMin) `shouldBe` True
2224
@@ -50,7 +52,7 @@ measureRate' desc t buffers threads rval consumerDelay producerDelay expectedRan
5052 <> ", consumer latency: " <> show consumerDelay
5153 <> ", producer latency: " <> show producerDelay)
5254 $ durationShouldBe expectedRange $
53− runStream
55+ S.drain
5456 $ (if consumerDelay > 0
5557 then S.mapM $ \x ->
5658 threadDelay (toMicroSecs consumerDelay) >> return x