Skip to content

Commit

Permalink
Fix flaky tests
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Telatynski <[email protected]>
  • Loading branch information
t3chguy committed Jan 13, 2025
1 parent 84dfc5d commit d7a1c30
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
3 changes: 1 addition & 2 deletions playwright/e2e/crypto/backups-mas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ test.describe("Key backup reset from elsewhere", () => {
await page.getByRole("textbox", { name: "Name" }).fill("test room");
await page.getByRole("button", { name: "Create room" }).click();

// @ts-ignore - this runs in the browser scope where mxMatrixClientPeg is a thing. Here, it is not.
const accessToken = await page.evaluate(() => mxMatrixClientPeg.get().getAccessToken());
const accessToken = await page.evaluate(() => window.mxMatrixClientPeg.get().getAccessToken());

const csAPI = new TestClientServerAPI(request, homeserver, accessToken);

Expand Down
5 changes: 5 additions & 0 deletions playwright/e2e/login/login-consent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ test.use({
},
},
},
context: async ({ context, homeserver }, use) => {
// Restart the homeserver to wipe its in-memory db so we can reuse the same user ID without cross-signing prompts
await homeserver.restart();
await use(context);
},
credentials: async ({ context, homeserver }, use) => {
const displayName = "Dave";
const credentials = await homeserver.registerUser(username, password, displayName);
Expand Down
3 changes: 2 additions & 1 deletion playwright/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ export const test = base.extend<{}, Services>({
{ scope: "worker" },
],

context: async ({ logger, context, request, homeserver }, use, testInfo) => {
context: async ({ logger, context, request, homeserver, mailhogClient }, use, testInfo) => {
homeserver.setRequest(request);
await logger.testStarted(testInfo);
await use(context);
await logger.testFinished(testInfo);
await mailhogClient.deleteAll();
},
});
6 changes: 5 additions & 1 deletion playwright/stale-screenshot-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ const snapshotRoot = path.join(__dirname, "snapshots");

class StaleScreenshotReporter implements Reporter {
private screenshots = new Set<string>();
private failing = false;
private success = true;

public onTestEnd(test: TestCase): void {
if (!test.ok()) return;
if (!test.ok()) {
this.failing = true;
}
for (const annotation of test.annotations) {
if (annotation.type === "_screenshot") {
this.screenshots.add(annotation.description);
Expand All @@ -40,6 +43,7 @@ class StaleScreenshotReporter implements Reporter {
}

public async onExit(): Promise<void> {
if (this.failing) return;
const screenshotFiles = new Set(await glob(`**/*.png`, { cwd: snapshotRoot }));
for (const screenshot of screenshotFiles) {
if (screenshot.split("-").at(-1) !== "linux.png") {
Expand Down
8 changes: 8 additions & 0 deletions playwright/testcontainers/mas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ const DEFAULT_CONFIG = {
access_token_ttl: 300,
compat_token_ttl: 300,
},
rate_limiting: {
login: {
burst: 1000,
},
registration: {
burst: 1000,
},
},
};

export class MatrixAuthenticationServiceContainer extends GenericContainer {
Expand Down
7 changes: 6 additions & 1 deletion playwright/testcontainers/synapse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
Please see LICENSE files in the repository root for full details.
*/

import { AbstractStartedContainer, GenericContainer, StartedTestContainer, Wait } from "testcontainers";
import { AbstractStartedContainer, GenericContainer, RestartOptions, StartedTestContainer, Wait } from "testcontainers";
import { APIRequestContext } from "@playwright/test";
import crypto from "node:crypto";
import * as YAML from "yaml";
Expand Down Expand Up @@ -239,6 +239,11 @@ export class StartedSynapseContainer extends AbstractStartedContainer implements
super(container);
}

public restart(options?: Partial<RestartOptions>): Promise<void> {
this.adminToken = undefined;
return super.restart(options);
}

public setRequest(request: APIRequestContext): void {
this.request = request;
}
Expand Down

0 comments on commit d7a1c30

Please sign in to comment.