-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/async-runner
- Loading branch information
Showing
4 changed files
with
303 additions
and
221 deletions.
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 |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { TEST_RUNNER_LOOKUP } from "./test-runner.mjs"; | ||
import { WarmupSuite } from "./benchmark-runner.mjs"; | ||
|
||
// FIXME: Create RemoteSuiteRunner subclass. | ||
export class SuiteRunner { | ||
#frame; | ||
#page; | ||
#params; | ||
#suite; | ||
#client; | ||
#suiteResults; | ||
|
||
constructor(frame, page, params, suite, client, measuredValues) { | ||
// FIXME: Create SuiteRunner-local measuredValues. | ||
this.#suiteResults = measuredValues.tests[suite.name]; | ||
if (!this.#suiteResults) { | ||
this.#suiteResults = { tests: {}, total: 0 }; | ||
measuredValues.tests[suite.name] = this.#suiteResults; | ||
} | ||
this.#frame = frame; | ||
this.#page = page; | ||
this.#client = client; | ||
this.#suite = suite; | ||
this.#params = params; | ||
} | ||
|
||
async run() { | ||
await this._prepareSuite(); | ||
await this._runSuite(); | ||
} | ||
|
||
async _prepareSuite() { | ||
const suiteName = this.#suite.name; | ||
const suitePrepareStartLabel = `suite-${suiteName}-prepare-start`; | ||
const suitePrepareEndLabel = `suite-${suiteName}-prepare-end`; | ||
|
||
performance.mark(suitePrepareStartLabel); | ||
await this._loadFrame(); | ||
await this.#suite.prepare(this.#page); | ||
performance.mark(suitePrepareEndLabel); | ||
|
||
performance.measure(`suite-${suiteName}-prepare`, suitePrepareStartLabel, suitePrepareEndLabel); | ||
} | ||
|
||
async _runSuite() { | ||
const suiteName = this.#suite.name; | ||
const suiteStartLabel = `suite-${suiteName}-start`; | ||
const suiteEndLabel = `suite-${suiteName}-end`; | ||
|
||
performance.mark(suiteStartLabel); | ||
for (const test of this.#suite.tests) { | ||
if (this.#client?.willRunTest) | ||
await this.#client.willRunTest(this.#suite, test); | ||
|
||
const testRunnerClass = TEST_RUNNER_LOOKUP[suite.type ?? "default"]; | ||
const testRunner = new testRunnerClass(this.#frame, this.#page, this.#params, this.#suite, test, this._recordTestResults); | ||
await testRunner.runTest(); | ||
} | ||
performance.mark(suiteEndLabel); | ||
|
||
performance.measure(`suite-${suiteName}`, suiteStartLabel, suiteEndLabel); | ||
this._validateSuiteTotal(); | ||
} | ||
|
||
_validateSuiteTotal() { | ||
// When the test is fast and the precision is low (for example with Firefox' | ||
// privacy.resistFingerprinting preference), it's possible that the measured | ||
// total duration for an entire is 0. | ||
const suiteTotal = this.#suiteResults.total; | ||
if (suiteTotal === 0) | ||
throw new Error(`Got invalid 0-time total for suite ${this.#suite.name}: ${suiteTotal}`); | ||
} | ||
|
||
async _loadFrame() { | ||
return new Promise((resolve, reject) => { | ||
const frame = this.#frame; | ||
frame.onload = () => resolve(); | ||
frame.onerror = () => reject(); | ||
frame.src = this.#suite.url; | ||
}); | ||
} | ||
|
||
_recordTestResults = async (test, syncTime, asyncTime) => { | ||
// Skip reporting updates for the warmup suite. | ||
if (this.#suite === WarmupSuite) | ||
return; | ||
|
||
const total = syncTime + asyncTime; | ||
this.#suiteResults.tests[test.name] = { tests: { Sync: syncTime, Async: asyncTime }, total: total }; | ||
this.#suiteResults.total += total; | ||
|
||
if (this.#client?.didRunTest) | ||
await this.#client.didRunTest(this.#suite, test); | ||
}; | ||
} | ||
|
||
// FIXME: implement remote steps | ||
class RemoteSuiteRunner extends SuiteRunner {} | ||
|
||
export const SUITE_RUNNER_LOOKUP = { | ||
__proto__: null, | ||
default: SuiteRunner, | ||
async: SuiteRunner, | ||
remote: RemoteSuiteRunner, | ||
}; |
Oops, something went wrong.