Skip to content

Commit d785435

Browse files
committed
Review fixes
1 parent c02ca1b commit d785435

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

servant-client/servant-client.cabal

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,15 @@ test-suite spec
112112

113113
-- Additonal dependencies
114114
build-depends:
115-
deepseq >= 1.3.0.2 && < 1.5
116-
, generics-sop >= 0.3.1.0 && < 0.4
117-
, hspec >= 2.4.4 && < 2.5
118-
, HUnit >= 1.6 && < 1.7
119-
, network >= 2.6.3.2 && < 2.7
120-
, QuickCheck >= 2.10.1 && < 2.12
121-
, servant == 0.13.*
122-
, servant-server == 0.13.*
115+
deepseq >= 1.3.0.2 && < 1.5
116+
, generics-sop >= 0.3.1.0 && < 0.4
117+
, hspec >= 2.4.4 && < 2.5
118+
, HUnit >= 1.6 && < 1.7
119+
, random-bytestring >= 0.1 && < 0.2
120+
, network >= 2.6.3.2 && < 2.7
121+
, QuickCheck >= 2.10.1 && < 2.12
122+
, servant == 0.13.*
123+
, servant-server == 0.13.*
123124

124125
build-tool-depends:
125126
hspec-discover:hspec-discover >= 2.4.4 && < 2.5

servant-client/test/Servant/StreamSpec.hs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ 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 (currentBytesUsed, getGCStats)
32+
import GHC.Stats
3333
import qualified Network.HTTP.Client as C
3434
import Prelude ()
3535
import Prelude.Compat
36-
import System.IO (IOMode (ReadMode), withFile)
3736
import System.IO.Unsafe (unsafePerformIO)
3837
import Test.Hspec
39-
import Test.QuickCheck
4038

4139
import Servant.API ((:<|>) ((:<|>)), (:>), JSON,
4240
NetstringFraming, NewlineFraming,
@@ -46,6 +44,7 @@ import Servant.Client
4644
import Servant.ClientSpec (Person (..))
4745
import qualified Servant.ClientSpec as CS
4846
import Servant.Server
47+
import Data.ByteString.Random.MWC (random)
4948

5049

5150
spec :: Spec
@@ -81,17 +80,17 @@ server = serve sapi
8180
:<|> return (StreamGenerator lotsGenerator)
8281
where
8382
lotsGenerator f r = do
84-
f ""
85-
withFile "/dev/urandom" ReadMode $
86-
\handle -> streamFiveMBNTimes handle 1000 r
83+
_ <- f ""
84+
streamFiveMBNTimes 1000 r
8785
return ()
8886

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

9695

9796

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

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

stack.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ extra-deps:
1818
- aeson-compat-0.3.7.1
1919
- free-5.0.1
2020
- lens-4.16
21+
- random-bytestring-0.1.3
22+
- pcg-random-0.1.3.5
2123

2224
# allow-newer: true # ignores all bounds, that's a sledgehammer
2325
# - doc/tutorial/

0 commit comments

Comments
 (0)