Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'testWithApplication'' function #843

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions warp/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 3.3.16

* Add `testWithApplication'` function
Same as `testWithApplication` but accepts pure `Application` instead of `IO Application`

## 3.3.15

* Using http2 v3.
Expand Down
1 change: 1 addition & 0 deletions warp/Network/Wai/Handler/Warp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ module Network.Wai.Handler.Warp (
, withApplication
, withApplicationSettings
, testWithApplication
, testWithApplication'
, testWithApplicationSettings
, openFreePort
-- * Version
Expand Down
15 changes: 15 additions & 0 deletions warp/Network/Wai/Handler/Warp/WithApplication.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Network.Wai.Handler.Warp.WithApplication (
withApplication,
withApplicationSettings,
testWithApplication,
testWithApplication',
testWithApplicationSettings,
openFreePort,
withFreePort,
Expand Down Expand Up @@ -48,6 +49,20 @@ withApplicationSettings settings' mkApp action = do
Left () -> throwIO $ ErrorCall "Unexpected: runSettingsSocket exited"
Right x -> return x

-- | Same as 'testWithApplication'
-- but accepts @app :: 'Application'@ as a first argument instead of @mkApp :: 'IO' 'Application'@.
--
-- Except for the purity of its first argument, the behaviour of this function is identical to 'testWithApplication'.
--
-- 'testWithApplication' can be expressed via 'testWithApplication'' as:
--
-- >>> testWithApplication mkApp action = mkApp >>= flip testWithApplication' action
--
-- @since 3.3.16
testWithApplication' :: Application -> (Port -> IO a) -> IO a
testWithApplication' =
testWithApplication . return

-- | Same as 'withApplication' but with different exception handling: If the
-- given 'Application' throws an exception, 'testWithApplication' will re-throw
-- the exception to the calling thread, possibly interrupting the execution of
Expand Down
7 changes: 7 additions & 0 deletions warp/test/WithApplicationSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ spec = do
readProcess "curl" ["-s", "localhost:" ++ show port] "")
`shouldThrow` (errorCall "foo")

describe "testWithApplication'" $ do
it "propagates exceptions from the server to the executing thread" $ do
let mkApp _request _respond = throwIO $ ErrorCall "foo"
(testWithApplication' mkApp $ \ port -> do
readProcess "curl" ["-s", "localhost:" ++ show port] "")
`shouldThrow` (errorCall "foo")

{- The future netwrok library will not export MkSocket.
describe "withFreePort" $ do
it "closes the socket before exiting" $ do
Expand Down
2 changes: 1 addition & 1 deletion warp/warp.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: warp
Version: 3.3.15
Version: 3.3.16
Synopsis: A fast, light-weight web server for WAI applications.
License: MIT
License-file: LICENSE
Expand Down