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

integration/testConsumeTempEvents: Remove race causing flaky test #4372

Merged
merged 1 commit into from
Dec 18, 2024
Merged
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
45 changes: 29 additions & 16 deletions integration/test/Test/Events.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,41 @@ testConsumeTempEvents = do
alice <- randomUser OwnDomain def

client0 <- addClient alice def {acapabilities = Just ["consumable-notifications"]} >>= getJSON 201
runCodensity (createEventsWebSocket alice Nothing) $ \ws -> do
clientId <- objId client0
clientId0 <- objId client0

void $ assertEvent ws $ \e -> do
e %. "type" `shouldMatch` "event"
e %. "data.event.payload.0.type" `shouldMatch` "user.client-add"
e %. "data.event.payload.0.client.id" `shouldMatch` clientId
lowerCodensity $ do
ws0 <- createEventsWebSocket alice (Just clientId0)

ackEvent ws e
-- Ensure there is no race between event for this client being pushed and temp
-- consumer being created
lift $ do
expectAndAckNewClientEvent ws0 clientId0
assertNoEvent_ ws0

runCodensity (createEventsWebSocket alice Nothing) $ \ws -> do
client <- addClient alice def {acapabilities = Just ["consumable-notifications"]} >>= getJSON 201
clientId <- objId client
wsTemp <- createEventsWebSocket alice Nothing

void $ assertEvent ws $ \e -> do
e %. "type" `shouldMatch` "event"
e %. "data.event.payload.0.type" `shouldMatch` "user.client-add"
e %. "data.event.payload.0.client.id" `shouldMatch` clientId
lift $ do
client1 <- addClient alice def {acapabilities = Just ["consumable-notifications"]} >>= getJSON 201
clientId1 <- objId client1

ackEvent ws e
-- Temp client gets this event as it happens after temp client has started
-- listening
void $ expectAndAckNewClientEvent wsTemp clientId1

assertNoEvent_ ws
-- Client0 should also be notified even if there is a temp client
void $ expectAndAckNewClientEvent ws0 clientId1

assertNoEvent_ wsTemp
assertNoEvent_ ws0
where
expectAndAckNewClientEvent :: EventWebSocket -> String -> App ()
expectAndAckNewClientEvent ws cid =
assertEvent ws $ \e -> do
e %. "type" `shouldMatch` "event"
e %. "data.event.payload.0.type" `shouldMatch` "user.client-add"
e %. "data.event.payload.0.client.id" `shouldMatch` cid

ackEvent ws e

testMLSTempEvents :: (HasCallStack) => App ()
testMLSTempEvents = do
Expand Down
Loading