Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Add a timeout to awaitRoomMembership
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Oct 11, 2024
1 parent 78e81cb commit d72a509
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions playwright/pages/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ export class Client {
*
* This is often useful after joining a room, when we need to wait for the sync loop to catch up.
*
* Times out with an error after 1 second.
*
* @param roomId - ID of the room to check
* @param membership - required membership.
*/
Expand All @@ -308,9 +310,17 @@ export class Client {
cli.logger.info(`waiting for room ${roomId}: membership now ${myMembership}`);
return myMembership === membership;
};
if (isReady()) return;
//if (isReady()) return;

const timeoutPromise = new Promise((resolve) => setTimeout(resolve, 1000)).then(() => {
const room = cli.getRoom(roomId);
const myMembership = room?.getMyMembership();
throw new Error(
`Timeout waiting for room ${roomId} membership (now '${myMembership}', wanted '${membership}')`,
);
});

return new Promise<void>((resolve) => {
const readyPromise = new Promise<void>((resolve) => {
async function onEvent() {
if (isReady()) {
cli.removeListener(window.matrixcs.ClientEvent.Event, onEvent);
Expand All @@ -320,6 +330,8 @@ export class Client {

cli.on(window.matrixcs.ClientEvent.Event, onEvent);
});

return Promise.race([timeoutPromise, readyPromise]);
},
{ roomId, membership },
);
Expand Down

0 comments on commit d72a509

Please sign in to comment.