Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flashdesignory committed Nov 15, 2024
1 parent c9d334e commit 0e1b954
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 66 deletions.
6 changes: 3 additions & 3 deletions resources/suite-runner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { WarmupSuite } from "./benchmark-runner.mjs";
// FIXME: Create AsyncSuiteRunner subclass.
// FIXME: Create RemoteSuiteRunner subclass.
export class SuiteRunner {
#suiteResults;
#frame;
#page;
#client;
#suite;
#params;
#suite;
#client;
#suiteResults;

constructor(frame, page, params, suite, client, measuredValues) {
// FIXME: Create SuiteRunner-local measuredValues.
Expand Down
98 changes: 37 additions & 61 deletions resources/test-runner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { TEST_INVOKER_LOOKUP } from "./test-invoker.mjs";
export class TestRunner {
#frame;
#page;
#callback;
#params;
#suite;
#test;
#params;
#callback;

constructor(frame, page, params, suite, test, callback) {
this.#suite = suite;
Expand All @@ -30,15 +30,44 @@ export class TestRunner {
let syncTime;
let asyncStartTime;
let asyncTime;

const runSync = () => {
this._runWarmup();
syncTime = this._measureSyncTime(syncStartLabel, syncEndLabel);
asyncStartTime = this._initAsyncTime(asyncStartLabel);
if (this.#params.warmupBeforeSync) {
performance.mark("warmup-start");
const startTime = performance.now();
// Infinite loop for the specified ms.
while (performance.now() - startTime < this.#params.warmupBeforeSync)
continue;
performance.mark("warmup-end");
}
performance.mark(syncStartLabel);
const syncStartTime = performance.now();
this.#test.run(this.#page);
const syncEndTime = performance.now();
performance.mark(syncEndLabel);

syncTime = syncEndTime - syncStartTime;

performance.mark(asyncStartLabel);
asyncStartTime = performance.now();
};
const measureAsync = () => {
this._forceLayout();
asyncTime = this._measureAsyncTime(asyncStartTime, asyncEndLabel);
this._measureTestPerformance(suiteName, testName, syncStartLabel, syncEndLabel, asyncStartLabel, asyncEndLabel);
const bodyReference = this.#frame ? this.#frame.contentDocument.body : document.body;
const windowReference = this.#frame ? this.#frame.contentWindow : window;
// Some browsers don't immediately update the layout for paint.
// Force the layout here to ensure we're measuring the layout time.
const height = bodyReference.getBoundingClientRect().height;
windowReference._unusedHeightValue = height; // Prevent dead code elimination.

const asyncEndTime = performance.now();
performance.mark(asyncEndLabel);

asyncTime = asyncEndTime - asyncStartTime;

if (this.#params.warmupBeforeSync)
performance.measure("warmup", "warmup-start", "warmup-end");
performance.measure(`${suiteName}.${testName}-sync`, syncStartLabel, syncEndLabel);
performance.measure(`${suiteName}.${testName}-async`, asyncStartLabel, asyncEndLabel);
};

const report = () => this.#callback(this.#test, syncTime, asyncTime);
Expand All @@ -47,57 +76,4 @@ export class TestRunner {

return invoker.start();
}

_runWarmup() {
if (this.#params.warmupBeforeSync) {
performance.mark("warmup-start");
const startTime = performance.now();
// Infinite loop for the specified ms.
while (performance.now() - startTime < this.#params.warmupBeforeSync)
continue;
performance.mark("warmup-end");
}
}

_measureSyncTime(syncStartLabel, syncEndLabel) {
performance.mark(syncStartLabel);
const syncStartTime = performance.now();
this.#test.run(this.#page);
const syncEndTime = performance.now();
performance.mark(syncEndLabel);

const syncTime = syncEndTime - syncStartTime;
return syncTime;
}

_initAsyncTime(asyncStartLabel) {
performance.mark(asyncStartLabel);

const asyncStartTime = performance.now();
return asyncStartTime;
}

_measureAsyncTime(asyncStartTime, asyncEndLabel) {
const asyncEndTime = performance.now();
performance.mark(asyncEndLabel);

const asyncTime = asyncEndTime - asyncStartTime;
return asyncTime;
}

_measureTestPerformance(suiteName, testName, syncStartLabel, syncEndLabel, asyncStartLabel, asyncEndLabel, params) {
if (this.#params.warmupBeforeSync)
performance.measure("warmup", "warmup-start", "warmup-end");
performance.measure(`${suiteName}.${testName}-sync`, syncStartLabel, syncEndLabel);
performance.measure(`${suiteName}.${testName}-async`, asyncStartLabel, asyncEndLabel);
}

_forceLayout() {
const bodyReference = this.#frame ? this.#frame.contentDocument.body : document.body;
const windowReference = this.#frame ? this.#frame.contentWindow : window;
// Some browsers don't immediately update the layout for paint.
// Force the layout here to ensure we're measuring the layout time.
const height = bodyReference.getBoundingClientRect().height;
windowReference._unusedHeightValue = height; // Prevent dead code elimination.
}
}
4 changes: 2 additions & 2 deletions tests/benchmark-runner-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ describe("BenchmarkRunner", () => {
runner._suite = suite;
await runner._appendFrame();
performanceMarkSpy = spy(window.performance, "mark");
const suiteRunner = new SuiteRunner(runner._measuredValues, runner._frame, runner._page, runner._client, suite, params);
const suiteRunner = new SuiteRunner(runner._frame, runner._page, params, suite, runner._client, runner._measuredValues);
await suiteRunner._runSuite();
});

Expand Down Expand Up @@ -235,7 +235,7 @@ describe("BenchmarkRunner", () => {
stubPerformanceNowCalls(syncStart, syncEnd, asyncStart, asyncEnd);

// instantiate recorded test results
const suiteRunner = new SuiteRunner(runner._measuredValues, runner._frame, runner._page, runner._client, suite, params);
const suiteRunner = new SuiteRunner(runner._frame, runner._page, params, suite, runner._client, runner._measuredValues);
await suiteRunner._runSuite();

await runner._finalize();
Expand Down

0 comments on commit 0e1b954

Please sign in to comment.