Skip to content

Commit

Permalink
integration/testConsumeTempEvents: Remove race causing flaky test (#4372
Browse files Browse the repository at this point in the history
)

The creation of temp queue races with client creation event. This is removed by
first expecting the event to be served to the real client and then listening to
events temporarily
  • Loading branch information
akshaymankar authored Dec 18, 2024
1 parent 0a966e1 commit 102a274
Showing 1 changed file with 29 additions and 16 deletions.
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

0 comments on commit 102a274

Please sign in to comment.