Skip to content
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
1 change: 1 addition & 0 deletions services/federator/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ mkDerivation {
];
testHaskellDepends = [
aeson
async
base
bytestring
bytestring-conversion
Expand Down
1 change: 1 addition & 0 deletions services/federator/federator.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ test-suite federator-tests

build-depends:
aeson
, async
, base
, bytestring
, bytestring-conversion
Expand Down
2 changes: 1 addition & 1 deletion services/federator/src/Federator/MockServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ mockInternalRequest remoteCalls mock targetDomain component (RPC path) req cont
if path == "api-version"
then pure $ MockResponse Wai.status200 "application/json" (Aeson.encode (VersionInfo mock.versions))
else do
modifyIORef remoteCalls (<> [fedRequest])
atomicModifyIORef' remoteCalls (\xs -> (xs <> [fedRequest], ()))
fromException @MockException
. handle (throw . handleException)
$ mock.handler fedRequest
Expand Down
16 changes: 16 additions & 0 deletions services/federator/test/unit/Test/Federator/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

module Test.Federator.Client (tests) where

import Control.Concurrent.Async (replicateConcurrently_)
import Control.Exception hiding (handle)
import Control.Monad.Codensity
import Control.Monad.Except
Expand Down Expand Up @@ -92,6 +93,7 @@ tests =
testGroup
"HTTP2 client"
[ testCase "testResponseHeaders" testResponseHeaders,
testCase "testConcurrentRequestsAllRecorded" testConcurrentRequestsAllRecorded,
testCase "testStreaming" testStreaming
]
]
Expand Down Expand Up @@ -248,6 +250,20 @@ testResponseHeaders = do
responseStatusCode resp @?= HTTP.status200
lookup "X-Foo" (toList (responseHeaders resp)) @?= Just "bar"

testConcurrentRequestsAllRecorded :: IO ()
testConcurrentRequestsAllRecorded = do
(_, sentRequests) <-
withTempMockFederator def $ \port -> do
let req =
HTTP2.requestBuilder
HTTP.methodPost
"/rpc/target.example.com/brig/test"
[("Wire-Origin-Domain", "origin.example.com"), (federationRequestIdHeaderName, "rid")]
"body"
mgr <- defaultHttp2Manager
replicateConcurrently_ 50 (performHTTP2Request mgr (False, "127.0.0.1", port) req)
length sentRequests @?= 50

testStreaming :: IO ()
testStreaming = withInfiniteMockServer $ \port -> do
let req = HTTP2.requestBuilder HTTP.methodPost "test" [] mempty
Expand Down