git.iko.soy/typeable/servant
on master help sign in
Review fixes
commitd78543575bc9f46ceadc465dfaecb8b2cd815524 authorJulian K. Arni <jkarni@gmail.com> dateMon 19 Mar 2018, 11:02 (9 years ago) parentc02ca1b
3 files changed+25−19
servant-client/servant-client.cabal+9−8 servant-client/test/Servant/StreamSpec.hs+14−11 stack.yaml+2
servant-client/servant-client.cabal+9−8
@@ -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+14−11
@@ -29,14 +29,12 @@ module Servant.StreamSpec (spec) where
2929import Control.Monad (replicateM_, void)
3030import qualified Data.ByteString as BS
3131import Data.Proxy
32−import GHC.Stats (currentBytesUsed, getGCStats)
32+import GHC.Stats
3333import qualified Network.HTTP.Client as C
3434import Prelude ()
3535import Prelude.Compat
36−import System.IO (IOMode (ReadMode), withFile)
3736import System.IO.Unsafe (unsafePerformIO)
3837import Test.Hspec
39−import Test.QuickCheck
4038
4139import Servant.API ((:<|>) ((:<|>)), (:>), JSON,
4240 NetstringFraming, NewlineFraming,
@@ -46,6 +44,7 @@ import Servant.Client
4644import Servant.ClientSpec (Person (..))
4745import qualified Servant.ClientSpec as CS
4846import Servant.Server
47+import Data.ByteString.Random.MWC (random)
4948
5049
5150spec :: 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
135138megabytes :: Num a => a -> a
136−megabytes n = n * (1000 ^ 2)
139+megabytes n = n * (1000 ^ (2 :: Int))
stack.yaml+2
@@ -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/