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

[WPB-5241] add the timeout to the global and local environment #3692

Merged
Merged
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
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ export INTEGRATION_DYNAMIC_BACKENDS_POOLSIZE=3
export AWS_REGION="eu-west-1"
export AWS_ACCESS_KEY_ID="dummykey"
export AWS_SECRET_ACCESS_KEY="dummysecret"

# integration test suite timeout
export TEST_TIMEOUT_SECONDS=2
1 change: 1 addition & 0 deletions changelog.d/2-features/WPB-5241
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add a uniform timeout to the integration test-suite set by the environment variable TEST_TIMEOUT_SECONDS with a default of 10 seconds if the variable isn't set
6 changes: 3 additions & 3 deletions integration/test/MLS/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ consumingMessages mp = Codensity $ \k -> do
-- each new user and wait for its join event
when (mls.protocol == MLSProtocolMLS) $
traverse_
(awaitMatch 10 isMemberJoinNotif)
(awaitMatch isMemberJoinNotif)
( flip Map.restrictKeys newUsers
. Map.mapKeys ((.user) . fst)
. Map.fromList
Expand All @@ -564,7 +564,7 @@ consumingMessages mp = Codensity $ \k -> do
consumeMessage :: HasCallStack => ClientIdentity -> Maybe MessagePackage -> WebSocket -> App Value
consumeMessage cid mmp ws = do
mls <- getMLSState
notif <- awaitMatch 10 isNewMLSMessageNotif ws
notif <- awaitMatch isNewMLSMessageNotif ws
event <- notif %. "payload.0"

for_ mmp $ \mp -> do
Expand Down Expand Up @@ -623,7 +623,7 @@ sendAndConsumeCommitBundle mp = do
consumeWelcome :: HasCallStack => ClientIdentity -> MessagePackage -> WebSocket -> App ()
consumeWelcome cid mp ws = do
mls <- getMLSState
notif <- awaitMatch 10 isWelcomeNotif ws
notif <- awaitMatch isWelcomeNotif ws
event <- notif %. "payload.0"

shouldMatch (eventSubConv event) (fromMaybe A.Null mls.convId)
Expand Down
12 changes: 5 additions & 7 deletions integration/test/Notifications.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Notifications where

import API.Gundeck
import Control.Monad.Extra
import Control.Monad.Reader (asks)
import Testlib.Prelude
import UnliftIO.Concurrent

Expand All @@ -11,14 +12,13 @@ awaitNotifications ::
user ->
client ->
Maybe String ->
-- | Timeout in seconds
Int ->
-- | Max no. of notifications
Int ->
-- | Selection function. Should not throw any exceptions
(Value -> App Bool) ->
App [Value]
awaitNotifications user client since0 tSecs n selector =
awaitNotifications user client since0 n selector = do
tSecs <- asks timeOutSeconds
assertAwaitResult =<< go tSecs since0 (AwaitResult False n [] [])
where
go 0 _ res = pure res
Expand Down Expand Up @@ -52,12 +52,11 @@ awaitNotification ::
user ->
client ->
Maybe lastNotifId ->
Int ->
(Value -> App Bool) ->
App Value
awaitNotification user client lastNotifId tSecs selector = do
awaitNotification user client lastNotifId selector = do
since0 <- mapM objId lastNotifId
head <$> awaitNotifications user client since0 tSecs 1 selector
head <$> awaitNotifications user client since0 1 selector

isDeleteUserNotif :: MakesValue a => a -> App Bool
isDeleteUserNotif n =
Expand Down Expand Up @@ -130,7 +129,6 @@ assertLeaveNotification fromUser conv user client leaver =
user
client
noValue
2
( allPreds
[ isConvLeaveNotif,
isNotifConv conv,
Expand Down
2 changes: 1 addition & 1 deletion integration/test/Test/AccessUpdate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ testAccessUpdateWithRemotes = do
withWebSockets [alice, bob, charlie] $ \wss -> do
void $ updateAccess alice conv update >>= getJSON 200
for_ wss $ \ws -> do
notif <- awaitMatch 10 isConvAccessUpdateNotif ws
notif <- awaitMatch isConvAccessUpdateNotif ws
notif %. "payload.0.qualified_conversation" `shouldMatch` objQidObject conv
notif %. "payload.0.qualified_from" `shouldMatch` objQidObject alice
notif %. "payload.0.data.access" `shouldMatch` update_access_value
Expand Down
24 changes: 12 additions & 12 deletions integration/test/Test/Conversation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ testAddUnreachableUserFromFederatingBackend = do
conv <-
postConversation alice (defProteus {qualifiedUsers = [bob, charlie]})
>>= getJSON 201
forM_ wss $ awaitMatch 5 isMemberJoinNotif
forM_ wss $ awaitMatch isMemberJoinNotif
pure conv
chadId <- chad %. "qualified_id"
pure (alice, chadId, conv)
Expand Down Expand Up @@ -505,10 +505,10 @@ testSynchroniseUserRemovalNotification = do
bindResponse (removeMember alice conv charlie) $ \resp ->
resp.status `shouldMatchInt` 200
runCodensity (startDynamicBackend dynBackend mempty) $ \_ -> do
nameNotif <- awaitNotification charlie client noValue 2 isConvNameChangeNotif
nameNotif <- awaitNotification charlie client noValue isConvNameChangeNotif
nameNotif %. "payload.0.qualified_conversation" `shouldMatch` objQidObject conv
nameNotif %. "payload.0.data.name" `shouldMatch` newConvName
leaveNotif <- awaitNotification charlie client noValue 2 isConvLeaveNotif
leaveNotif <- awaitNotification charlie client noValue isConvLeaveNotif
leaveNotif %. "payload.0.qualified_conversation" `shouldMatch` objQidObject conv

testConvRenaming :: HasCallStack => App ()
Expand All @@ -521,7 +521,7 @@ testConvRenaming = do
withWebSockets [alice, bob] $ \wss -> do
for_ wss $ \ws -> do
void $ changeConversationName alice conv newConvName >>= getBody 200
nameNotif <- awaitMatch 10 isConvNameChangeNotif ws
nameNotif <- awaitMatch isConvNameChangeNotif ws
nameNotif %. "payload.0.data.name" `shouldMatch` newConvName
nameNotif %. "payload.0.qualified_conversation" `shouldMatch` objQidObject conv

Expand All @@ -534,7 +534,7 @@ testReceiptModeWithRemotesOk = do
withWebSockets [alice, bob] $ \wss -> do
void $ updateReceiptMode alice conv (43 :: Int) >>= getBody 200
for_ wss $ \ws -> do
notif <- awaitMatch 10 isReceiptModeUpdateNotif ws
notif <- awaitMatch isReceiptModeUpdateNotif ws
notif %. "payload.0.qualified_conversation" `shouldMatch` objQidObject conv
notif %. "payload.0.qualified_from" `shouldMatch` objQidObject alice
notif %. "payload.0.data.receipt_mode" `shouldMatchInt` 43
Expand All @@ -550,7 +550,7 @@ testReceiptModeWithRemotesUnreachable = do
>>= getJSON 201
withWebSocket alice $ \ws -> do
void $ updateReceiptMode alice conv (43 :: Int) >>= getBody 200
notif <- awaitMatch 10 isReceiptModeUpdateNotif ws
notif <- awaitMatch isReceiptModeUpdateNotif ws
notif %. "payload.0.qualified_conversation" `shouldMatch` objQidObject conv
notif %. "payload.0.qualified_from" `shouldMatch` objQidObject alice
notif %. "payload.0.data.receipt_mode" `shouldMatchInt` 43
Expand Down Expand Up @@ -608,7 +608,7 @@ testDeleteRemoteMemberRemoteUnreachable = do
void $ withWebSockets [alice, bob] $ \wss -> do
void $ removeMember alice conv bob >>= getBody 200
for wss $ \ws -> do
leaveNotif <- awaitMatch 10 isConvLeaveNotif ws
leaveNotif <- awaitMatch isConvLeaveNotif ws
leaveNotif %. "payload.0.qualified_conversation" `shouldMatch` objQidObject conv
leaveNotif %. "payload.0.qualified_from" `shouldMatch` objQidObject alice
leaveNotif %. "payload.0.data.qualified_user_ids.0" `shouldMatch` objQidObject bob
Expand All @@ -629,7 +629,7 @@ testDeleteTeamConversationWithRemoteMembers = do
void $ withWebSockets [alice, bob] $ \wss -> do
void $ deleteTeamConversation team conv alice >>= getBody 200
for wss $ \ws -> do
notif <- awaitMatch 10 isConvDeleteNotif ws
notif <- awaitMatch isConvDeleteNotif ws
notif %. "payload.0.qualified_conversation" `shouldMatch` objQidObject conv
notif %. "payload.0.qualified_from" `shouldMatch` objQidObject alice

Expand All @@ -654,10 +654,10 @@ testDeleteTeamConversationWithUnreachableRemoteMembers = do
pure (bob, bobClient)
withWebSocket alice $ \ws -> do
void $ deleteTeamConversation team conv alice >>= getBody 200
notif <- awaitMatch 10 isConvDeleteNotif ws
notif <- awaitMatch isConvDeleteNotif ws
assertNotification notif
void $ runCodensity (startDynamicBackend dynBackend mempty) $ \_ -> do
notif <- awaitNotification bob bobClient noValue 2 isConvDeleteNotif
notif <- awaitNotification bob bobClient noValue isConvDeleteNotif
assertNotification notif

testLeaveConversationSuccess :: HasCallStack => App ()
Expand Down Expand Up @@ -705,7 +705,7 @@ testOnUserDeletedConversations = do

void $ withWebSocket alex $ \ws -> do
void $ deleteUser bob >>= getBody 200
n <- awaitMatch 10 isConvLeaveNotif ws
n <- awaitMatch isConvLeaveNotif ws
n %. "payload.0.qualified_from" `shouldMatch` bobId
n %. "payload.0.qualified_conversation" `shouldMatch` (mainConvBefore %. "qualified_id")

Expand All @@ -732,7 +732,7 @@ testUpdateConversationByRemoteAdmin = do
void $ updateRole alice bob "wire_admin" (conv %. "qualified_id") >>= getBody 200
void $ withWebSockets [alice, bob, charlie] $ \wss -> do
void $ updateReceiptMode bob conv (41 :: Int) >>= getBody 200
for_ wss $ \ws -> awaitMatch 10 isReceiptModeUpdateNotif ws
for_ wss $ \ws -> awaitMatch isReceiptModeUpdateNotif ws

testGuestCreatesConversation :: HasCallStack => App ()
testGuestCreatesConversation = do
Expand Down
2 changes: 1 addition & 1 deletion integration/test/Test/Demo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ testWebSockets = do
user <- randomUser OwnDomain def
withWebSocket user $ \ws -> do
client <- BrigP.addClient user def >>= getJSON 201
n <- awaitMatch 3 (\n -> nPayload n %. "type" `isEqual` "user.client-add") ws
n <- awaitMatch (\n -> nPayload n %. "type" `isEqual` "user.client-add") ws
nPayload n %. "client.id" `shouldMatch` (client %. "id")

testMultipleBackends :: App ()
Expand Down
14 changes: 7 additions & 7 deletions integration/test/Test/Federation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ testNotificationsForOfflineBackends = do
isDelUserLeaveUpConvNotif = allPreds [isConvLeaveNotif, isNotifConv upBackendConv, isNotifForUser delUser]

do
newMsgNotif <- awaitMatch 10 isNewMessageNotif ws
newMsgNotif <- awaitMatch isNewMessageNotif ws
newMsgNotif %. "payload.0.qualified_conversation" `shouldMatch` objQidObject upBackendConv
newMsgNotif %. "payload.0.data.text" `shouldMatchBase64` "success message for other user"

void $ awaitMatch 10 isOtherUser2LeaveUpConvNotif ws
void $ awaitMatch 10 isDelUserLeaveUpConvNotif ws
void $ awaitMatch isOtherUser2LeaveUpConvNotif ws
void $ awaitMatch isDelUserLeaveUpConvNotif ws

delUserDeletedNotif <- nPayload $ awaitMatch 10 isDeleteUserNotif ws
delUserDeletedNotif <- nPayload $ awaitMatch isDeleteUserNotif ws
objQid delUserDeletedNotif `shouldMatch` objQid delUser

runCodensity (startDynamicBackend downBackend mempty) $ \_ -> do
newMsgNotif <- awaitNotification downUser1 downClient1 noValue 5 isNewMessageNotif
newMsgNotif <- awaitNotification downUser1 downClient1 noValue isNewMessageNotif
newMsgNotif %. "payload.0.qualified_conversation" `shouldMatch` objQidObject upBackendConv
newMsgNotif %. "payload.0.data.text" `shouldMatchBase64` "success message for down user"

Expand All @@ -124,11 +124,11 @@ testNotificationsForOfflineBackends = do
isNotifConv downBackendConv,
isNotifForUser delUser
]
void $ awaitNotification downUser1 downClient1 (Just newMsgNotif) 5 isDelUserLeaveDownConvNotif
void $ awaitNotification downUser1 downClient1 (Just newMsgNotif) isDelUserLeaveDownConvNotif

-- FUTUREWORK: Uncomment after fixing this bug: https://wearezeta.atlassian.net/browse/WPB-3664
-- void $ awaitNotification downUser1 downClient1 (Just newMsgNotif) 1 isOtherUser2LeaveUpConvNotif
-- void $ awaitNotification otherUser otherClient (Just newMsgNotif) 1 isDelUserLeaveDownConvNotif

delUserDeletedNotif <- nPayload $ awaitNotification downUser1 downClient1 (Just newMsgNotif) 5 isDeleteUserNotif
delUserDeletedNotif <- nPayload $ awaitNotification downUser1 downClient1 (Just newMsgNotif) isDeleteUserNotif
objQid delUserDeletedNotif `shouldMatch` objQid delUser
17 changes: 8 additions & 9 deletions integration/test/Test/MLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ testSendMessageNoReturnToSender = do
void . bindResponse (postMLSMessage mp.sender mp.message) $ \resp -> do
resp.status `shouldMatchInt` 201
for_ wss $ \ws -> do
n <- awaitMatch 3 (\n -> nPayload n %. "type" `isEqual` "conversation.mls-message-add") ws
n <- awaitMatch (\n -> nPayload n %. "type" `isEqual` "conversation.mls-message-add") ws
nPayload n %. "data" `shouldMatch` T.decodeUtf8 (Base64.encode mp.message)
expectFailure (const $ pure ()) $
awaitMatch
3
( \n ->
liftM2
(&&)
Expand Down Expand Up @@ -93,7 +92,7 @@ testMixedProtocolUpgrade secondDomain = do
modifyMLSState $ \mls -> mls {protocol = MLSProtocolMixed}

for_ websockets $ \ws -> do
n <- awaitMatch 3 (\value -> nPayload value %. "type" `isEqual` "conversation.protocol-update") ws
n <- awaitMatch (\value -> nPayload value %. "type" `isEqual` "conversation.protocol-update") ws
nPayload n %. "data.protocol" `shouldMatch` "mixed"

bindResponse (getConversation alice qcnv) $ \resp -> do
Expand Down Expand Up @@ -145,7 +144,7 @@ testMixedProtocolAddUsers secondDomain = do
mp <- createAddCommit alice1 [bob]
welcome <- assertJust "should have welcome" mp.welcome
void $ sendAndConsumeCommitBundle mp
n <- awaitMatch 3 (\n -> nPayload n %. "type" `isEqual` "conversation.mls-welcome") ws
n <- awaitMatch (\n -> nPayload n %. "type" `isEqual` "conversation.mls-welcome") ws
nPayload n %. "data" `shouldMatch` T.decodeUtf8 (Base64.encode welcome)

testMixedProtocolUserLeaves :: HasCallStack => Domain -> App ()
Expand Down Expand Up @@ -177,7 +176,7 @@ testMixedProtocolUserLeaves secondDomain = do
bindResponse (removeConversationMember bob qcnv) $ \resp ->
resp.status `shouldMatchInt` 200

n <- awaitMatch 3 (\n -> nPayload n %. "type" `isEqual` "conversation.mls-message-add") ws
n <- awaitMatch (\n -> nPayload n %. "type" `isEqual` "conversation.mls-message-add") ws

msg <- asByteString (nPayload n %. "data") >>= showMessage alice1
let leafIndexBob = 1
Expand Down Expand Up @@ -293,7 +292,7 @@ testMLSProtocolUpgrade secondDomain = do
-- charlie is added to the group
void $ uploadNewKeyPackage charlie1
void $ createAddCommit alice1 [charlie] >>= sendAndConsumeCommitBundle
awaitMatch 10 isNewMLSMessageNotif ws
awaitMatch isNewMLSMessageNotif ws

supportMLS alice
bindResponse (putConversationProtocol bob conv "mls") $ \resp -> do
Expand All @@ -310,7 +309,7 @@ testMLSProtocolUpgrade secondDomain = do
resp.status `shouldMatchInt` 200
modifyMLSState $ \mls -> mls {protocol = MLSProtocolMLS}
for_ wss $ \ws -> do
n <- awaitMatch 3 isNewMLSMessageNotif ws
n <- awaitMatch isNewMLSMessageNotif ws
msg <- asByteString (nPayload n %. "data") >>= showMessage alice1
let leafIndexCharlie = 2
msg %. "message.content.body.Proposal.Remove.removed" `shouldMatchInt` leafIndexCharlie
Expand Down Expand Up @@ -377,7 +376,7 @@ testRemoteRemoveClient = do
withWebSocket alice $ \wsAlice -> do
void $ deleteClient bob bob1.client >>= getBody 200
let predicate n = nPayload n %. "type" `isEqual` "conversation.mls-message-add"
n <- awaitMatch 5 predicate wsAlice
n <- awaitMatch predicate wsAlice
shouldMatch (nPayload n %. "conversation") (objId conv)
shouldMatch (nPayload n %. "from") (objId bob)

Expand Down Expand Up @@ -527,7 +526,7 @@ testLocalWelcome = do
es <- sendAndConsumeCommitBundle commit
let isWelcome n = nPayload n %. "type" `isEqual` "conversation.mls-welcome"

n <- awaitMatch 5 isWelcome wsBob
n <- awaitMatch isWelcome wsBob

shouldMatch (nPayload n %. "conversation") (objId qcnv)
shouldMatch (nPayload n %. "from") (objId alice)
Expand Down
18 changes: 9 additions & 9 deletions integration/test/Test/MLS/Message.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ testApplicationMessage = do
withWebSockets [alice, alex, bob, betty] $ \wss -> do
-- alice adds all other users (including her own client)
void $ createAddCommit alice1 [alice, alex, bob, betty] >>= sendAndConsumeCommitBundle
traverse_ (awaitMatch 10 isMemberJoinNotif) wss
traverse_ (awaitMatch isMemberJoinNotif) wss

-- alex sends a message
void $ createApplicationMessage alex1 "hello" >>= sendAndConsumeMessage
traverse_ (awaitMatch 10 isNewMLSMessageNotif) wss
traverse_ (awaitMatch isNewMLSMessageNotif) wss

-- bob sends a message
void $ createApplicationMessage bob1 "hey" >>= sendAndConsumeMessage
traverse_ (awaitMatch 10 isNewMLSMessageNotif) wss
traverse_ (awaitMatch isNewMLSMessageNotif) wss

testAppMessageSomeReachable :: HasCallStack => App ()
testAppMessageSomeReachable = do
Expand All @@ -67,7 +67,7 @@ testAppMessageSomeReachable = do
void $ createNewGroup alice1
void $ withWebSocket charlie $ \ws -> do
void $ createAddCommit alice1 [bob, charlie] >>= sendAndConsumeCommitBundle
awaitMatch 10 isMemberJoinNotif ws
awaitMatch isMemberJoinNotif ws
pure alice1

-- charlie isn't able to receive this message, so we make sure we can post it
Expand All @@ -88,7 +88,7 @@ testMessageNotifications bobDomain = do

void $ withWebSocket bob $ \ws -> do
void $ createAddCommit alice1 [alice, bob] >>= sendAndConsumeCommitBundle
awaitMatch 10 isMemberJoinNotif ws
awaitMatch isMemberJoinNotif ws

let get (opts :: GetNotifications) = do
notifs <- getNotifications bob opts {size = Just 10000} >>= getJSON 200
Expand All @@ -100,7 +100,7 @@ testMessageNotifications bobDomain = do

void $ withWebSocket bob $ \ws -> do
void $ createApplicationMessage alice1 "hi bob" >>= sendAndConsumeMessage
awaitMatch 10 isNewMLSMessageNotif ws
awaitMatch isNewMLSMessageNotif ws

get def `shouldMatchInt` (numNotifs + 1)
get def {client = Just bobClient} `shouldMatchInt` (numNotifsClient + 1)
Expand All @@ -114,10 +114,10 @@ testMultipleMessages = do

withWebSockets [bob] $ \wss -> do
void $ createAddCommit alice1 [bob] >>= sendAndConsumeCommitBundle
traverse_ (awaitMatch 10 isMemberJoinNotif) wss
traverse_ (awaitMatch isMemberJoinNotif) wss

void $ createApplicationMessage alice1 "hello" >>= sendAndConsumeMessage
traverse_ (awaitMatch 10 isNewMLSMessageNotif) wss
traverse_ (awaitMatch isNewMLSMessageNotif) wss

void $ createApplicationMessage alice1 "world" >>= sendAndConsumeMessage
traverse_ (awaitMatch 10 isNewMLSMessageNotif) wss
traverse_ (awaitMatch isNewMLSMessageNotif) wss
6 changes: 3 additions & 3 deletions integration/test/Test/MLS/One2One.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ testMLSOne2One scenario = do
void $ sendAndConsumeCommitBundle commit

let isWelcome n = nPayload n %. "type" `isEqual` "conversation.mls-welcome"
n <- awaitMatch 3 isWelcome ws
n <- awaitMatch isWelcome ws
nPayload n %. "data" `shouldMatch` B8.unpack (Base64.encode (fold commit.welcome))

void $ awaitMatch 3 isMemberJoinNotif ws
void $ awaitMatch isMemberJoinNotif ws

withWebSocket bob1 $ \ws -> do
mp <- createApplicationMessage alice1 "hello, world"
void $ sendAndConsumeMessage mp
let isMessage n = nPayload n %. "type" `isEqual` "conversation.mls-message-add"
n <- awaitMatch 3 isMessage ws
n <- awaitMatch isMessage ws
nPayload n %. "data" `shouldMatch` B8.unpack (Base64.encode mp.message)
Loading