Skip to content

Commit 7c901dc

Browse files
committed
Re-review changes.
Using random packages mysteriously fail on CI, and also uses a lot more CPU.
1 parent d785435 commit 7c901dc

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

servant-client/test/Servant/StreamSpec.hs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ module Servant.StreamSpec (spec) where
2929
import Control.Monad (replicateM_, void)
3030
import qualified Data.ByteString as BS
3131
import Data.Proxy
32-
import GHC.Stats
32+
import GHC.Stats (currentBytesUsed, getGCStats)
3333
import qualified Network.HTTP.Client as C
3434
import Prelude ()
3535
import Prelude.Compat
36+
import System.IO (IOMode (ReadMode), withFile)
3637
import System.IO.Unsafe (unsafePerformIO)
3738
import Test.Hspec
39+
import Test.QuickCheck
3840

3941
import Servant.API ((:<|>) ((:<|>)), (:>), JSON,
4042
NetstringFraming, NewlineFraming,
@@ -44,7 +46,6 @@ import Servant.Client
4446
import Servant.ClientSpec (Person (..))
4547
import qualified Servant.ClientSpec as CS
4648
import Servant.Server
47-
import Data.ByteString.Random.MWC (random)
4849

4950

5051
spec :: Spec
@@ -80,17 +81,17 @@ server = serve sapi
8081
:<|> return (StreamGenerator lotsGenerator)
8182
where
8283
lotsGenerator f r = do
83-
_ <- f ""
84-
streamFiveMBNTimes 1000 r
84+
f ""
85+
withFile "/dev/urandom" ReadMode $
86+
\handle -> streamFiveMBNTimes handle 1000 r
8587
return ()
8688

87-
streamFiveMBNTimes :: Int -> (BS.ByteString -> IO ()) -> IO ()
88-
streamFiveMBNTimes left sink
89-
| left <= 0 = return ()
89+
streamFiveMBNTimes handle left sink
90+
| left <= 0 = return ""
9091
| otherwise = do
91-
msg <- random (megabytes 5)
92+
msg <- BS.hGet handle (megabytes 5)
9293
sink msg
93-
streamFiveMBNTimes (left - 1) sink
94+
streamFiveMBNTimes handle (left - 1) sink
9495

9596

9697

@@ -128,12 +129,8 @@ streamSpec = beforeAll (CS.startWaiApp server) $ afterAll CS.endWaiApp $ do
128129
Right (ResultStream res) <- runClient getGetALot baseUrl
129130
let consumeNChunks n = replicateM_ n (res void)
130131
consumeNChunks 900
131-
#if MIN_VERSION_base(4,9,0)
132-
memUsed <- max_mem_in_use_bytes <$> getRTSStats
133-
#else
134132
memUsed <- currentBytesUsed <$> getGCStats
135-
#endif
136133
memUsed `shouldSatisfy` (< (megabytes 20))
137134

138135
megabytes :: Num a => a -> a
139-
megabytes n = n * (1000 ^ (2 :: Int))
136+
megabytes n = n * (1000 ^ 2)

0 commit comments

Comments
 (0)