1{-# LANGUAGE OverloadedStrings #-}
3module ExceptionSpec (main, spec) where
5import Control.Applicative
7import Control.Concurrent (forkIO, threadDelay)
10import Network.HTTP.Types hiding (Header)
11import Network.Wai hiding (Response)
12import Network.Wai.Internal (Request(..))
13import Network.Wai.Handler.Warp
14import System.IO.Unsafe (unsafePerformIO)
16import Control.Exception
17import qualified Data.Streaming.Network as N
18import Control.Concurrent.Async (withAsync)
19import Network.Socket (sClose)
24withTestServer :: (Int -> IO a) -> IO a
25withTestServer inner = bracket
26 (N.bindRandomPortTCP "*4")
28 $ \(port, lsocket) -> do
29 withAsync (runSettingsSocket defaultSettings lsocket testApp)
33testApp (Network.Wai.Internal.Request {pathInfo = [x]})
34 | x == "statusError" =
35 return $ responseLBS undefined [] "foo"
36 | x == "headersError" =
37 return $ responseLBS ok200 undefined "foo"
38 | x == "headerError" =
39 return $ responseLBS ok200 [undefined] "foo"
41 return $ responseLBS ok200 [] undefined
42 | x == "ioException" = do
43 void $ fail "ioException"
44 return $ responseLBS ok200 [] "foo"
46 return $ responseLBS ok200 [] "foo"
49spec = describe "responds even if there is an exception" $ do
50 {- Disabling these tests. We can consider forcing evaluation in Warp.
52 sc <- rspCode <$> sendGET "http://localhost:2345/statusError"
54 it "headersError" $ do
55 sc <- rspCode <$> sendGET "http://localhost:2345/headersError"
58 sc <- rspCode <$> sendGET "http://localhost:2345/headerError"
61 sc <- rspCode <$> sendGET "http://localhost:2345/bodyError"
64 it "ioException" $ withTestServer $ \port -> do
65 sc <- rspCode <$> sendGET (concat $ ["http://localhost:", show port, "/ioException"])
68----------------------------------------------------------------
70sendGET :: String -> IO (Response String)
71sendGET url = sendGETwH url []
73sendGETwH :: String -> [Header] -> IO (Response String)
74sendGETwH url hdr = unResult $ simpleHTTP $ (getRequest url) { rqHeaders = hdr }
76unResult :: IO (Result (Response String)) -> IO (Response String)
80 Right rsp -> return rsp
81 Left _ -> error "Connection error"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list