Review fixes
This commit is contained in:
parent
c02ca1b6e1
commit
d78543575b
3 changed files with 25 additions and 19 deletions
|
@ -112,14 +112,15 @@ test-suite spec
|
|||
|
||||
-- Additonal dependencies
|
||||
build-depends:
|
||||
deepseq >= 1.3.0.2 && < 1.5
|
||||
, generics-sop >= 0.3.1.0 && < 0.4
|
||||
, hspec >= 2.4.4 && < 2.5
|
||||
, HUnit >= 1.6 && < 1.7
|
||||
, network >= 2.6.3.2 && < 2.7
|
||||
, QuickCheck >= 2.10.1 && < 2.12
|
||||
, servant == 0.13.*
|
||||
, servant-server == 0.13.*
|
||||
deepseq >= 1.3.0.2 && < 1.5
|
||||
, generics-sop >= 0.3.1.0 && < 0.4
|
||||
, hspec >= 2.4.4 && < 2.5
|
||||
, HUnit >= 1.6 && < 1.7
|
||||
, random-bytestring >= 0.1 && < 0.2
|
||||
, network >= 2.6.3.2 && < 2.7
|
||||
, QuickCheck >= 2.10.1 && < 2.12
|
||||
, servant == 0.13.*
|
||||
, servant-server == 0.13.*
|
||||
|
||||
build-tool-depends:
|
||||
hspec-discover:hspec-discover >= 2.4.4 && < 2.5
|
||||
|
|
|
@ -29,14 +29,12 @@ module Servant.StreamSpec (spec) where
|
|||
import Control.Monad (replicateM_, void)
|
||||
import qualified Data.ByteString as BS
|
||||
import Data.Proxy
|
||||
import GHC.Stats (currentBytesUsed, getGCStats)
|
||||
import GHC.Stats
|
||||
import qualified Network.HTTP.Client as C
|
||||
import Prelude ()
|
||||
import Prelude.Compat
|
||||
import System.IO (IOMode (ReadMode), withFile)
|
||||
import System.IO.Unsafe (unsafePerformIO)
|
||||
import Test.Hspec
|
||||
import Test.QuickCheck
|
||||
|
||||
import Servant.API ((:<|>) ((:<|>)), (:>), JSON,
|
||||
NetstringFraming, NewlineFraming,
|
||||
|
@ -46,6 +44,7 @@ import Servant.Client
|
|||
import Servant.ClientSpec (Person (..))
|
||||
import qualified Servant.ClientSpec as CS
|
||||
import Servant.Server
|
||||
import Data.ByteString.Random.MWC (random)
|
||||
|
||||
|
||||
spec :: Spec
|
||||
|
@ -81,17 +80,17 @@ server = serve sapi
|
|||
:<|> return (StreamGenerator lotsGenerator)
|
||||
where
|
||||
lotsGenerator f r = do
|
||||
f ""
|
||||
withFile "/dev/urandom" ReadMode $
|
||||
\handle -> streamFiveMBNTimes handle 1000 r
|
||||
_ <- f ""
|
||||
streamFiveMBNTimes 1000 r
|
||||
return ()
|
||||
|
||||
streamFiveMBNTimes handle left sink
|
||||
| left <= 0 = return ""
|
||||
streamFiveMBNTimes :: Int -> (BS.ByteString -> IO ()) -> IO ()
|
||||
streamFiveMBNTimes left sink
|
||||
| left <= 0 = return ()
|
||||
| otherwise = do
|
||||
msg <- BS.hGet handle (megabytes 5)
|
||||
msg <- random (megabytes 5)
|
||||
sink msg
|
||||
streamFiveMBNTimes handle (left - 1) sink
|
||||
streamFiveMBNTimes (left - 1) sink
|
||||
|
||||
|
||||
|
||||
|
@ -129,8 +128,12 @@ streamSpec = beforeAll (CS.startWaiApp server) $ afterAll CS.endWaiApp $ do
|
|||
Right (ResultStream res) <- runClient getGetALot baseUrl
|
||||
let consumeNChunks n = replicateM_ n (res void)
|
||||
consumeNChunks 900
|
||||
#if MIN_VERSION_base(4,9,0)
|
||||
memUsed <- max_mem_in_use_bytes <$> getRTSStats
|
||||
#else
|
||||
memUsed <- currentBytesUsed <$> getGCStats
|
||||
#endif
|
||||
memUsed `shouldSatisfy` (< (megabytes 20))
|
||||
|
||||
megabytes :: Num a => a -> a
|
||||
megabytes n = n * (1000 ^ 2)
|
||||
megabytes n = n * (1000 ^ (2 :: Int))
|
||||
|
|
|
@ -18,6 +18,8 @@ extra-deps:
|
|||
- aeson-compat-0.3.7.1
|
||||
- free-5.0.1
|
||||
- lens-4.16
|
||||
- random-bytestring-0.1.3
|
||||
- pcg-random-0.1.3.5
|
||||
|
||||
# allow-newer: true # ignores all bounds, that's a sledgehammer
|
||||
# - doc/tutorial/
|
||||
|
|
Loading…
Reference in a new issue