This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 830
Add basic performance testing via Cypress #8586
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c2a88d1
Silence Cypress window access from support modules
jryans e75f4b3
Add basic performance testing via Cypress
jryans 9438a4d
Remove leftovers
jryans 8be46ba
Fix types
jryans 6081ba9
Fix register measurement
jryans 558d087
Merge remote-tracking branch 'origin/develop' into jryans/performance…
jryans 60b4d20
Only add measurements when we have some
jryans 30dc7a1
Use the spec name as the measurement category
jryans 61b28ac
Only run benchmarking on develop
jryans cfc88e7
Remove unused alert configuration
jryans File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,17 +40,16 @@ jobs: | |
test/end-to-end-tests/synapse/installations/consent/homeserver.log | ||
retention-days: 14 | ||
|
||
- name: Download previous benchmark data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a dead block, as we aren't using the "separate file" version of this benchmark action. |
||
uses: actions/cache@v1 | ||
with: | ||
path: ./cache | ||
key: ${{ runner.os }}-benchmark | ||
|
||
- name: Store benchmark result | ||
uses: matrix-org/github-action-benchmark@jsperfentry-1 | ||
with: | ||
tool: 'jsperformanceentry' | ||
output-file-path: test/end-to-end-tests/performance-entries.json | ||
# This is the default dashboard path. It's included here anyway to | ||
# make the difference from the Cypress variant in | ||
# `element-build-and-test.yaml` more obvious. | ||
# The dashboard is available at https://matrix-org.github.io/matrix-react-sdk/dev/bench/ | ||
benchmark-data-dir-path: dev/bench | ||
fail-on-alert: false | ||
comment-on-alert: false | ||
# Only temporary to monitor where failures occur | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
/// <reference types="cypress" /> | ||
|
||
import * as path from "path"; | ||
import * as fse from "fs-extra"; | ||
|
||
import PluginEvents = Cypress.PluginEvents; | ||
import PluginConfigOptions = Cypress.PluginConfigOptions; | ||
|
||
// This holds all the performance measurements throughout the run | ||
let bufferedMeasurements: PerformanceEntry[] = []; | ||
|
||
function addMeasurements(measurements: PerformanceEntry[]): void { | ||
bufferedMeasurements = bufferedMeasurements.concat(measurements); | ||
return null; | ||
} | ||
|
||
async function writeMeasurementsFile() { | ||
try { | ||
const measurementsPath = path.join("cypress", "performance", "measurements.json"); | ||
await fse.outputJSON(measurementsPath, bufferedMeasurements, { | ||
spaces: 4, | ||
}); | ||
} finally { | ||
bufferedMeasurements = []; | ||
} | ||
} | ||
|
||
export function performance(on: PluginEvents, config: PluginConfigOptions) { | ||
on("task", { addMeasurements }); | ||
on("after:run", writeMeasurementsFile); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
/// <reference types="cypress" /> | ||
|
||
import Chainable = Cypress.Chainable; | ||
import AUTWindow = Cypress.AUTWindow; | ||
|
||
declare global { | ||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
namespace Cypress { | ||
interface Chainable { | ||
/** | ||
* Start measuring the duration of some task. | ||
* @param task The task name. | ||
*/ | ||
startMeasuring(task: string): Chainable<AUTWindow>; | ||
/** | ||
* Stop measuring the duration of some task. | ||
* The duration is reported in the Cypress log. | ||
* @param task The task name. | ||
*/ | ||
stopMeasuring(task: string): Chainable<AUTWindow>; | ||
} | ||
} | ||
} | ||
|
||
const PREFIX = "cy:"; | ||
|
||
function startMeasuring(task: string): Chainable<AUTWindow> { | ||
return cy.window({ log: false }).then((win) => { | ||
win.mxPerformanceMonitor.start(PREFIX + task); | ||
}); | ||
} | ||
|
||
function stopMeasuring(task: string): Chainable<AUTWindow> { | ||
return cy.window({ log: false }).then((win) => { | ||
const measure = win.mxPerformanceMonitor.stop(PREFIX + task); | ||
cy.log(`**${task}** ${measure.duration} ms`); | ||
}); | ||
} | ||
|
||
Cypress.Commands.add("startMeasuring", startMeasuring); | ||
Cypress.Commands.add("stopMeasuring", stopMeasuring); | ||
|
||
Cypress.on("window:before:unload", (event: BeforeUnloadEvent) => { | ||
const doc = event.target as Document; | ||
if (doc.location.href === "about:blank") return; | ||
const win = doc.defaultView as AUTWindow; | ||
if (!win.mxPerformanceMonitor) return; | ||
const entries = win.mxPerformanceMonitor.getEntries().filter(entry => { | ||
return entry.name.startsWith(PREFIX); | ||
}); | ||
cy.task("addMeasurements", entries); | ||
}); | ||
|
||
// Needed to make this file a module | ||
export { }; | ||
Comment on lines
+73
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah that's the thing I was missing for the two files with dummy imports 🤦 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not enable either of these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could do, up to the team really. The current configuration is just copied from a previous usage of this benchmarking action. Perhaps it would be good to get a few data points in the dashboard and then define an appropriate threshold for alerting?