Skip to content

Commit

Permalink
[feat] add asked timeout to Notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
MangoIV committed Nov 6, 2023
1 parent 4756802 commit 98d674e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
12 changes: 5 additions & 7 deletions integration/test/Notifications.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import API.Gundeck
import Control.Monad.Extra
import Testlib.Prelude
import UnliftIO.Concurrent
import Control.Monad.Reader (asks)

awaitNotifications ::
(HasCallStack, MakesValue user, MakesValue client) =>
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
6 changes: 3 additions & 3 deletions integration/test/Test/Conversation.hs
Original file line number Diff line number Diff line change
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 Down Expand Up @@ -657,7 +657,7 @@ testDeleteTeamConversationWithUnreachableRemoteMembers = do
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
6 changes: 3 additions & 3 deletions integration/test/Test/Federation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ testNotificationsForOfflineBackends = do
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

0 comments on commit 98d674e

Please sign in to comment.