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

Commit

Permalink
Fix flakiness of cypress crypto tests (#8731)
Browse files Browse the repository at this point in the history
  • Loading branch information
duxovni committed Jun 1, 2022
1 parent e11dbae commit 23cc1af
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions cypress/integration/7-crypto/crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ limitations under the License.
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
import { SynapseInstance } from "../../plugins/synapsedocker";

function waitForEncryption(cli: MatrixClient, roomId: string, win: Cypress.AUTWindow, resolve: () => void) {
cli.crypto.cryptoStore.getEndToEndRooms(null, (result) => {
if (result[roomId]) {
resolve();
} else {
cli.once(win.matrixcs.RoomStateEvent.Update, () => waitForEncryption(cli, roomId, win, resolve));
}
function waitForEncryption(cli: MatrixClient, roomId: string, win: Cypress.AUTWindow): Promise<void> {
return new Promise<void>(resolve => {
const onEvent = () => {
cli.crypto.cryptoStore.getEndToEndRooms(null, (result) => {
if (result[roomId]) {
cli.off(win.matrixcs.ClientEvent.Event, onEvent);
resolve();
}
});
};
cli.on(win.matrixcs.ClientEvent.Event, onEvent);
});
}

Expand Down Expand Up @@ -61,15 +65,15 @@ describe("Cryptography", () => {
cy.window(),
]).then(([bot, roomId, win]) => {
cy.inviteUser(roomId, bot.getUserId());
cy.visit("/#/room/" + roomId);
cy.wrap(
new Promise<void>(resolve =>
waitForEncryption(bot, roomId, win, resolve),
waitForEncryption(
bot, roomId, win,
).then(() => bot.sendMessage(roomId, {
body: "Top secret message",
msgtype: "m.text",
})),
);
cy.visit("/#/room/" + roomId);
});

cy.get(".mx_RoomView_body .mx_cryptoEvent").should("contain", "Encryption enabled");
Expand Down

0 comments on commit 23cc1af

Please sign in to comment.