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

Commit c122c5c

Browse files
authored
Add basic performance testing via Cypress (#8586)
1 parent 83b3dfa commit c122c5c

File tree

17 files changed

+169
-18
lines changed

17 files changed

+169
-18
lines changed

.github/workflows/element-build-and-test.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ jobs:
8888
cypress/videos
8989
cypress/synapselogs
9090
91+
- name: Store benchmark result
92+
if: github.ref == 'refs/heads/develop'
93+
uses: matrix-org/github-action-benchmark@jsperfentry-1
94+
with:
95+
name: Cypress measurements
96+
tool: 'jsperformanceentry'
97+
output-file-path: cypress/performance/measurements.json
98+
# The dashboard is available at https://matrix-org.github.io/matrix-react-sdk/cypress/bench/
99+
benchmark-data-dir-path: cypress/bench
100+
fail-on-alert: false
101+
comment-on-alert: false
102+
github-token: ${{ secrets.DEPLOY_GH_PAGES }}
103+
auto-push: ${{ github.ref == 'refs/heads/develop' }}
104+
91105
app-tests:
92106
name: Element Web Integration Tests
93107
runs-on: ubuntu-latest

.github/workflows/end-to-end-tests.yaml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,18 @@ jobs:
4040
test/end-to-end-tests/synapse/installations/consent/homeserver.log
4141
retention-days: 14
4242
43-
- name: Download previous benchmark data
44-
uses: actions/cache@v1
45-
with:
46-
path: ./cache
47-
key: ${{ runner.os }}-benchmark
48-
4943
- name: Store benchmark result
44+
if: github.ref == 'refs/heads/develop'
5045
uses: matrix-org/github-action-benchmark@jsperfentry-1
5146
with:
5247
tool: 'jsperformanceentry'
5348
output-file-path: test/end-to-end-tests/performance-entries.json
49+
# This is the default dashboard path. It's included here anyway to
50+
# make the difference from the Cypress variant in
51+
# `element-build-and-test.yaml` more obvious.
52+
# The dashboard is available at https://matrix-org.github.io/matrix-react-sdk/dev/bench/
53+
benchmark-data-dir-path: dev/bench
5454
fail-on-alert: false
5555
comment-on-alert: false
56-
# Only temporary to monitor where failures occur
57-
alert-comment-cc-users: '@gsouquet'
5856
github-token: ${{ secrets.DEPLOY_GH_PAGES }}
5957
auto-push: ${{ github.ref == 'refs/heads/develop' }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ package-lock.json
2727
# These could have files in them but don't currently
2828
# Cypress will still auto-create them though...
2929
/cypress/fixtures
30+
/cypress/performance

cypress/global.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import "matrix-js-sdk/src/@types/global";
1818
import type { MatrixClient, ClientEvent } from "matrix-js-sdk/src/client";
1919
import type { RoomMemberEvent } from "matrix-js-sdk/src/models/room-member";
2020
import type { MatrixDispatcher } from "../src/dispatcher/dispatcher";
21+
import type PerformanceMonitor from "../src/performance";
2122

2223
declare global {
2324
// eslint-disable-next-line @typescript-eslint/no-namespace
@@ -27,6 +28,7 @@ declare global {
2728
matrixClient?: MatrixClient;
2829
};
2930
mxDispatcher: MatrixDispatcher;
31+
mxPerformanceMonitor: PerformanceMonitor;
3032
beforeReload?: boolean; // for detecting reloads
3133
// Partial type for the matrix-js-sdk module, exported by browser-matrix
3234
matrixcs: {
@@ -38,7 +40,11 @@ declare global {
3840
}
3941

4042
interface Window {
41-
mxDispatcher: MatrixDispatcher; // to appease the MatrixDispatcher import
43+
// to appease the MatrixDispatcher import
44+
mxDispatcher: MatrixDispatcher;
45+
// to appease the PerformanceMonitor import
46+
mxPerformanceMonitor: PerformanceMonitor;
47+
mxPerformanceEntryNames: any;
4248
}
4349
}
4450

cypress/integration/1-register/register.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ describe("Registration", () => {
4242
cy.get("#mx_RegistrationForm_username").type("alice");
4343
cy.get("#mx_RegistrationForm_password").type("totally a great password");
4444
cy.get("#mx_RegistrationForm_passwordConfirm").type("totally a great password");
45+
cy.startMeasuring("create-account");
4546
cy.get(".mx_Login_submit").click();
4647

4748
cy.get(".mx_RegistrationEmailPromptDialog button.mx_Dialog_primary").click();
49+
cy.stopMeasuring("create-account");
4850
cy.get(".mx_InteractiveAuthEntryComponents_termsPolicy input").click();
51+
cy.startMeasuring("from-submit-to-home");
4952
cy.get(".mx_InteractiveAuthEntryComponents_termsSubmit").click();
5053
cy.url().should('contain', '/#/home');
54+
cy.stopMeasuring("from-submit-to-home");
5155
});
5256
});

cypress/integration/2-login/login.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ describe("Login", () => {
4949

5050
cy.get("#mx_LoginForm_username").type(username);
5151
cy.get("#mx_LoginForm_password").type(password);
52+
cy.startMeasuring("from-submit-to-home");
5253
cy.get(".mx_Login_submit").click();
5354

5455
cy.url().should('contain', '/#/home');
56+
cy.stopMeasuring("from-submit-to-home");
5557
});
5658
});
5759
});

cypress/integration/4-create-room/create-room.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ describe("Create Room", () => {
5454
// Fill room address
5555
cy.get('[label="Room address"]').type("test-room-1");
5656
// Submit
57+
cy.startMeasuring("from-submit-to-room");
5758
cy.get(".mx_Dialog_primary").click();
5859
});
5960

6061
cy.url().should("contain", "/#/room/#test-room-1:localhost");
62+
cy.stopMeasuring("from-submit-to-room");
6163
cy.get(".mx_RoomHeader_nametext").contains(name);
6264
cy.get(".mx_RoomHeader_topic").contains(topic);
6365
});

cypress/plugins/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ limitations under the License.
1616

1717
/// <reference types="cypress" />
1818

19-
import { synapseDocker } from "./synapsedocker";
2019
import PluginEvents = Cypress.PluginEvents;
2120
import PluginConfigOptions = Cypress.PluginConfigOptions;
21+
import { performance } from "./performance";
22+
import { synapseDocker } from "./synapsedocker";
2223

2324
/**
2425
* @type {Cypress.PluginConfig}
2526
*/
2627
export default function(on: PluginEvents, config: PluginConfigOptions) {
28+
performance(on, config);
2729
synapseDocker(on, config);
2830
}

cypress/plugins/performance.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
/// <reference types="cypress" />
18+
19+
import * as path from "path";
20+
import * as fse from "fs-extra";
21+
22+
import PluginEvents = Cypress.PluginEvents;
23+
import PluginConfigOptions = Cypress.PluginConfigOptions;
24+
25+
// This holds all the performance measurements throughout the run
26+
let bufferedMeasurements: PerformanceEntry[] = [];
27+
28+
function addMeasurements(measurements: PerformanceEntry[]): void {
29+
bufferedMeasurements = bufferedMeasurements.concat(measurements);
30+
return null;
31+
}
32+
33+
async function writeMeasurementsFile() {
34+
try {
35+
const measurementsPath = path.join("cypress", "performance", "measurements.json");
36+
await fse.outputJSON(measurementsPath, bufferedMeasurements, {
37+
spaces: 4,
38+
});
39+
} finally {
40+
bufferedMeasurements = [];
41+
}
42+
}
43+
44+
export function performance(on: PluginEvents, config: PluginConfigOptions) {
45+
on("task", { addMeasurements });
46+
on("after:run", writeMeasurementsFile);
47+
}

cypress/plugins/synapsedocker/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ async function synapseStop(id: string): Promise<void> {
201201
synapses.delete(id);
202202

203203
console.log(`Stopped synapse id ${id}.`);
204-
// cypres deliberately fails if you return 'undefined', so
204+
// cypress deliberately fails if you return 'undefined', so
205205
// return null to signal all is well and we've handled the task.
206206
return null;
207207
}

0 commit comments

Comments
 (0)