on master help sign in
More resilient tests (again)
cd08dd7Michael Snoyman
warp/test/RunSpec.hs+3−3
@@ -4,7 +4,8 @@
4module RunSpec (main, spec, withApp) where
4module RunSpec (main, spec, withApp) where
5
5
6import Control.Concurrent (forkIO, killThread, threadDelay)
6import Control.Concurrent (forkIO, killThread, threadDelay)
7−import Control.Monad (forM_)
7+import Control.Monad (forM_, replicateM_)
8+import System.Timeout (timeout)
8import Control.Monad.IO.Class (MonadIO, liftIO)
9import Control.Monad.IO.Class (MonadIO, liftIO)
9import Data.ByteString (ByteString, hPutStr, hGetSome)
10import Data.ByteString (ByteString, hPutStr, hGetSome)
10import qualified Data.ByteString as S
11import qualified Data.ByteString as S
@@ -102,8 +103,7 @@ runTest expected app chunks = do
102 withApp defaultSettings (app ref) $ \port -> do
103 withApp defaultSettings (app ref) $ \port -> do
103 handle <- connectTo "127.0.0.1" $ PortNumber $ fromIntegral port
104 handle <- connectTo "127.0.0.1" $ PortNumber $ fromIntegral port
104 forM_ chunks $ \chunk -> hPutStr handle chunk >> hFlush handle
105 forM_ chunks $ \chunk -> hPutStr handle chunk >> hFlush handle
105− _ <- hGetSome handle 4096
106+ _ <- timeout 100000 $ replicateM_ expected $ hGetSome handle 4096
106− threadDelay 30000
107 res <- I.readIORef ref
107 res <- I.readIORef ref
108 case res of
108 case res of
109 Left s -> error s
109 Left s -> error s