Skip to content

Commit 7b395c2

Browse files
pr feedback
1 parent ec2b883 commit 7b395c2

File tree

11 files changed

+191
-181
lines changed

11 files changed

+191
-181
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="./_next/static/css/a0dca1379a01e5cf.css" as="style"/><link rel="stylesheet" href="./_next/static/css/a0dca1379a01e5cf.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="./_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="./_next/static/chunks/webpack-e50e9853db18b759.js" defer=""></script><script src="./_next/static/chunks/framework-2c79e2a64abdb08b.js" defer=""></script><script src="./_next/static/chunks/main-2ba37e62325cc71b.js" defer=""></script><script src="./_next/static/chunks/pages/_app-77983e68be50f72a.js" defer=""></script><script src="./_next/static/chunks/pages/_error-54de1933a164a1ff.js" defer=""></script><script src="./_next/static/XRziDoLlUPkrw2MQfjPik/_buildManifest.js" defer=""></script><script src="./_next/static/XRziDoLlUPkrw2MQfjPik/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><div id="settings-container"></div><div id="notifications-container"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"XRziDoLlUPkrw2MQfjPik","assetPrefix":".","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
1+
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="./_next/static/css/a0dca1379a01e5cf.css" as="style"/><link rel="stylesheet" href="./_next/static/css/a0dca1379a01e5cf.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="./_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="./_next/static/chunks/webpack-e50e9853db18b759.js" defer=""></script><script src="./_next/static/chunks/framework-2c79e2a64abdb08b.js" defer=""></script><script src="./_next/static/chunks/main-2ba37e62325cc71b.js" defer=""></script><script src="./_next/static/chunks/pages/_app-77983e68be50f72a.js" defer=""></script><script src="./_next/static/chunks/pages/_error-54de1933a164a1ff.js" defer=""></script><script src="./_next/static/0WioSK_GYKwlHihOM6Gxq/_buildManifest.js" defer=""></script><script src="./_next/static/0WioSK_GYKwlHihOM6Gxq/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><div id="settings-container"></div><div id="notifications-container"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"0WioSK_GYKwlHihOM6Gxq","assetPrefix":".","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>

resources/newssite/news-next/dist/_next/static/XRziDoLlUPkrw2MQfjPik/_buildManifest.js renamed to resources/newssite/news-next/dist/_next/static/0WioSK_GYKwlHihOM6Gxq/_buildManifest.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/newssite/news-next/dist/_next/static/XRziDoLlUPkrw2MQfjPik/_ssgManifest.js renamed to resources/newssite/news-next/dist/_next/static/0WioSK_GYKwlHihOM6Gxq/_ssgManifest.js

File renamed without changes.

resources/newssite/news-next/dist/_next/static/chunks/pages/index-2c799f1d9400a895.js renamed to resources/newssite/news-next/dist/_next/static/chunks/pages/index-bca4656243ade034.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="./_next/static/css/a0dca1379a01e5cf.css" as="style"/><link rel="stylesheet" href="./_next/static/css/a0dca1379a01e5cf.css" data-n-g=""/><link rel="preload" href="./_next/static/css/2cf5163b53bb0adb.css" as="style"/><link rel="stylesheet" href="./_next/static/css/2cf5163b53bb0adb.css" data-n-p=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="./_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="./_next/static/chunks/webpack-e50e9853db18b759.js" defer=""></script><script src="./_next/static/chunks/framework-2c79e2a64abdb08b.js" defer=""></script><script src="./_next/static/chunks/main-2ba37e62325cc71b.js" defer=""></script><script src="./_next/static/chunks/pages/_app-77983e68be50f72a.js" defer=""></script><script src="./_next/static/chunks/743-fd706aeabb7828e3.js" defer=""></script><script src="./_next/static/chunks/pages/index-2c799f1d9400a895.js" defer=""></script><script src="./_next/static/XRziDoLlUPkrw2MQfjPik/_buildManifest.js" defer=""></script><script src="./_next/static/XRziDoLlUPkrw2MQfjPik/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><div id="settings-container"></div><div id="notifications-container"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{}},"page":"/","query":{},"buildId":"XRziDoLlUPkrw2MQfjPik","assetPrefix":".","nextExport":true,"autoExport":true,"isFallback":false,"scriptLoader":[]}</script></body></html>
1+
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="./_next/static/css/a0dca1379a01e5cf.css" as="style"/><link rel="stylesheet" href="./_next/static/css/a0dca1379a01e5cf.css" data-n-g=""/><link rel="preload" href="./_next/static/css/2cf5163b53bb0adb.css" as="style"/><link rel="stylesheet" href="./_next/static/css/2cf5163b53bb0adb.css" data-n-p=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="./_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="./_next/static/chunks/webpack-e50e9853db18b759.js" defer=""></script><script src="./_next/static/chunks/framework-2c79e2a64abdb08b.js" defer=""></script><script src="./_next/static/chunks/main-2ba37e62325cc71b.js" defer=""></script><script src="./_next/static/chunks/pages/_app-77983e68be50f72a.js" defer=""></script><script src="./_next/static/chunks/743-fd706aeabb7828e3.js" defer=""></script><script src="./_next/static/chunks/pages/index-bca4656243ade034.js" defer=""></script><script src="./_next/static/0WioSK_GYKwlHihOM6Gxq/_buildManifest.js" defer=""></script><script src="./_next/static/0WioSK_GYKwlHihOM6Gxq/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><div id="settings-container"></div><div id="notifications-container"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{}},"page":"/","query":{},"buildId":"0WioSK_GYKwlHihOM6Gxq","assetPrefix":".","nextExport":true,"autoExport":true,"isFallback":false,"scriptLoader":[]}</script></body></html>

resources/newssite/news-next/src/pages/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ import { HashRouter as Router, Routes, Route } from "react-router-dom";
33
import Page from "@/partials/page/page";
44
import Head from "next/head";
55
import { DataContextProvider } from "@/context/data-context";
6-
import { connectToBenchmark } from "speedometer-utils/workload-testing-utils.mjs";
6+
import { BenchmarkConnector } from "speedometer-utils/workload-testing-utils.mjs";
77
import { getBenchmarkSuitesManager } from "@/workload-test.mjs";
88

99
export default function App() {
1010
// Using 'useLayoutEffect' here, since this will connect the workload after all DOM mutations happened.
1111
// This ensures that all elemetns are in the DOM, prior to signaling to the Benchmark that the workload is ready to run a test suite.
1212
useEffect(() => {
13-
const disconnect = connectToBenchmark(getBenchmarkSuitesManager(), "news-next", 1);
14-
return disconnect;
13+
const benchmarkConnector = new BenchmarkConnector(getBenchmarkSuitesManager(), "news-next", 1);
14+
benchmarkConnector.connect();
15+
16+
return () => benchmarkConnector.disconnect();
1517
}, []);
1618

1719
return (

resources/newssite/news-next/src/workload-test.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { BenchmarkTestStep, BenchmarkTestSuite, BenchmarkSuitesManager, forceLayout, getElement } from "speedometer-utils/workload-testing-utils.mjs";
1+
import { BenchmarkStep, BenchmarkSuite, BenchmarkSuitesManager, forceLayout, getElement } from "speedometer-utils/workload-testing-utils.mjs";
22

33
export function getBenchmarkSuitesManager() {
44
return new BenchmarkSuitesManager(window.name, [
5-
new BenchmarkTestSuite("default", [
6-
new BenchmarkTestStep("Navigate-to-US-page", () => {
5+
new BenchmarkSuite("default", [
6+
new BenchmarkStep("Navigate-to-US-page", () => {
77
for (let i = 0; i < 25; i++) {
88
getElement("#navbar-dropdown-toggle").click();
99
forceLayout();
@@ -14,7 +14,7 @@ export function getBenchmarkSuitesManager() {
1414
getElement("#navbar-navlist-us-link").click();
1515
forceLayout();
1616
}),
17-
new BenchmarkTestStep("Navigate-to-World-page", () => {
17+
new BenchmarkStep("Navigate-to-World-page", () => {
1818
for (let i = 0; i < 25; i++) {
1919
getElement("#navbar-dropdown-toggle").click();
2020
forceLayout();
@@ -25,7 +25,7 @@ export function getBenchmarkSuitesManager() {
2525
getElement("#navbar-navlist-world-link").click();
2626
forceLayout();
2727
}),
28-
new BenchmarkTestStep("Navigate-to-Politics-page", () => {
28+
new BenchmarkStep("Navigate-to-Politics-page", () => {
2929
for (let i = 0; i < 25; i++) {
3030
getElement("#navbar-dropdown-toggle").click();
3131
forceLayout();

resources/shared/benchmark.mjs

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import { TestRunner } from "./test-runner.mjs";
2+
import { Params } from "./params.mjs";
3+
4+
/**
5+
* BenchmarkStep
6+
*
7+
* A single test step, with a common interface to interact with.
8+
*/
9+
export class BenchmarkStep {
10+
constructor(name, run) {
11+
this.name = name;
12+
this.run = run;
13+
}
14+
15+
async runAndRecord(params, suite, test, callback) {
16+
const testRunner = new TestRunner(null, null, params, suite, test, callback);
17+
const result = await testRunner.runTest();
18+
return result;
19+
}
20+
}
21+
22+
/**
23+
* BenchmarkSuite
24+
*
25+
* A single test suite that contains one or more test steps.
26+
*/
27+
export class BenchmarkSuite {
28+
constructor(name, tests) {
29+
this.name = name;
30+
this.tests = tests;
31+
}
32+
33+
record(_test, syncTime, asyncTime) {
34+
const total = syncTime + asyncTime;
35+
const results = {
36+
tests: { Sync: syncTime, Async: asyncTime },
37+
total: total,
38+
};
39+
40+
return results;
41+
}
42+
43+
async runAndRecord(params, onProgress) {
44+
const measuredValues = {
45+
tests: {},
46+
total: 0,
47+
};
48+
const suiteStartLabel = `suite-${this.name}-start`;
49+
const suiteEndLabel = `suite-${this.name}-end`;
50+
51+
performance.mark(suiteStartLabel);
52+
53+
for (const test of this.tests) {
54+
const result = await test.runAndRecord(params, this, test, this.record);
55+
measuredValues.tests[test.name] = result;
56+
measuredValues.total += result.total;
57+
onProgress?.(test.name);
58+
}
59+
60+
performance.mark(suiteEndLabel);
61+
performance.measure(`suite-${this.name}`, suiteStartLabel, suiteEndLabel);
62+
63+
return {
64+
type: "suite-tests-complete",
65+
status: "success",
66+
result: measuredValues,
67+
suitename: this.name,
68+
};
69+
}
70+
}
71+
72+
/**
73+
* BenchmarkSuitesManager
74+
*
75+
* A collection of test suites for a single workload.
76+
*/
77+
export class BenchmarkSuitesManager {
78+
constructor(name, suites) {
79+
this.name = name;
80+
this.suites = suites;
81+
}
82+
83+
getSuiteByName(name) {
84+
return this.suites.find((suite) => suite.name === name);
85+
}
86+
}
87+
88+
/** **********************************************************************
89+
* BenchmarkConnector
90+
*
91+
* postMessage is used to communicate between app and benchmark.
92+
* When the app is ready, an 'app-ready' message is sent to signal that the app can receive instructions.
93+
*
94+
* A prepare script within the apps appends window.name and window.version from the package.json file.
95+
* The appId is build by appending name-version
96+
* It's used as an additional safe-guard to ensure the correct app responds to a message.
97+
*************************************************************************/
98+
export class BenchmarkConnector {
99+
constructor(benchmarkSuitesManager, name, version) {
100+
this.benchmarkSuitesManager = benchmarkSuitesManager;
101+
this.name = name;
102+
this.version = version;
103+
104+
if (!name || !version)
105+
console.warn("No name or version supplied, to create a unique appId");
106+
107+
this.appId = name && version ? `${name}-${version}` : -1;
108+
this.onMessage = this.onMessage.bind(this);
109+
}
110+
111+
async onMessage(event) {
112+
if (event.data.id !== this.appId || event.data.key !== "benchmark-connector")
113+
return;
114+
115+
switch (event.data.type) {
116+
case "benchmark-suite":
117+
// eslint-disable-next-line no-case-declarations
118+
const params = new Params(new URLSearchParams(window.location.search));
119+
// eslint-disable-next-line no-case-declarations
120+
const { result } = await this.benchmarkSuitesManager.getSuiteByName(event.data.name).runAndRecord(params, (test) => this.sendMessage({ type: "step-complete", status: "success", appId: this.appId, name: this.name, test }));
121+
this.sendMessage({ type: "suite-complete", status: "success", appId: this.appId, result });
122+
this.disconnect();
123+
break;
124+
default:
125+
console.error(`Message data type not supported: ${event.data.type}`);
126+
}
127+
}
128+
129+
sendMessage(message) {
130+
window.top.postMessage(message, "*");
131+
}
132+
133+
connect() {
134+
window.addEventListener("message", this.onMessage);
135+
this.sendMessage({ type: "app-ready", status: "success", appId: this.appId });
136+
}
137+
138+
disconnect() {
139+
window.removeEventListener("message", this.onMessage);
140+
}
141+
}

resources/shared/helpers.mjs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Helper Methods
3+
*
4+
* Various methods that are extracted from the Page class.
5+
*/
6+
export function getParent(lookupStartNode, path) {
7+
lookupStartNode = lookupStartNode.shadowRoot ?? lookupStartNode;
8+
const parent = path.reduce((root, selector) => {
9+
const node = root.querySelector(selector);
10+
return node.shadowRoot ?? node;
11+
}, lookupStartNode);
12+
13+
return parent;
14+
}
15+
16+
export function getElement(selector, path = [], lookupStartNode = document) {
17+
const element = getParent(lookupStartNode, path).querySelector(selector);
18+
return element;
19+
}
20+
21+
export function getAllElements(selector, path = [], lookupStartNode = document) {
22+
const elements = Array.from(getParent(lookupStartNode, path).querySelectorAll(selector));
23+
return elements;
24+
}
25+
26+
export function forceLayout() {
27+
const rect = document.body.getBoundingClientRect();
28+
const e = document.elementFromPoint((rect.width / 2) | 0, (rect.height / 2) | 0);
29+
return e;
30+
}

0 commit comments

Comments
 (0)