Skip to content

Commit 617c731

Browse files
authored
SuiteRunner: use suite instance variables (#437)
* use suite directly * fix tests
1 parent 4719e3f commit 617c731

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

resources/benchmark-runner.mjs

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -551,65 +551,67 @@ export class SuiteRunner {
551551
}
552552

553553
async run() {
554-
// FIXME: use this._suite in all SuiteRunner methods directly.
555-
await this._prepareSuite(this._suite);
556-
await this._runSuite(this._suite);
554+
await this._prepareSuite();
555+
await this._runSuite();
557556
}
558557

559-
async _prepareSuite(suite) {
560-
const suiteName = suite.name;
558+
async _prepareSuite() {
559+
const suiteName = this._suite.name;
561560
const suitePrepareStartLabel = `suite-${suiteName}-prepare-start`;
562561
const suitePrepareEndLabel = `suite-${suiteName}-prepare-end`;
563562

564563
performance.mark(suitePrepareStartLabel);
565-
await this._loadFrame(suite);
566-
await suite.prepare(this._page);
564+
await this._loadFrame();
565+
await this._suite.prepare(this._page);
567566
performance.mark(suitePrepareEndLabel);
568567

569568
performance.measure(`suite-${suiteName}-prepare`, suitePrepareStartLabel, suitePrepareEndLabel);
570569
}
571570

572-
async _runSuite(suite) {
573-
const suiteName = suite.name;
571+
async _runSuite() {
572+
const suiteName = this._suite.name;
574573
const suiteStartLabel = `suite-${suiteName}-start`;
575574
const suiteEndLabel = `suite-${suiteName}-end`;
576575

577576
performance.mark(suiteStartLabel);
578-
for (const test of suite.tests)
579-
await this._runTestAndRecordResults(suite, test);
577+
for (const test of this._suite.tests)
578+
await this._runTestAndRecordResults(test);
580579
performance.mark(suiteEndLabel);
581580

582581
performance.measure(`suite-${suiteName}`, suiteStartLabel, suiteEndLabel);
583582
this._validateSuiteTotal(suiteName);
584583
}
585584

586-
_validateSuiteTotal(suiteName) {
585+
_validateSuiteTotal() {
587586
// When the test is fast and the precision is low (for example with Firefox'
588587
// privacy.resistFingerprinting preference), it's possible that the measured
589588
// total duration for an entire is 0.
589+
const suiteName = this._suite.name;
590590
const suiteTotal = this._measuredValues.tests[suiteName].total;
591591
if (suiteTotal === 0)
592592
throw new Error(`Got invalid 0-time total for suite ${suiteName}: ${suiteTotal}`);
593593
}
594594

595-
async _loadFrame(suite) {
595+
async _loadFrame() {
596596
return new Promise((resolve, reject) => {
597597
const frame = this._page._frame;
598598
frame.onload = () => resolve();
599599
frame.onerror = () => reject();
600-
frame.src = suite.url;
600+
frame.src = this._suite.url;
601601
});
602602
}
603603

604-
async _runTestAndRecordResults(suite, test) {
604+
async _runTestAndRecordResults(test) {
605605
if (this._client?.willRunTest)
606-
await this._client.willRunTest(suite, test);
606+
await this._client.willRunTest(this._suite, test);
607607

608608
// Prepare all mark labels outside the measuring loop.
609-
const startLabel = `${suite.name}.${test.name}-start`;
610-
const syncEndLabel = `${suite.name}.${test.name}-sync-end`;
611-
const asyncStartLabel = `${suite.name}.${test.name}-async-start`;
612-
const asyncEndLabel = `${suite.name}.${test.name}-async-end`;
609+
const suiteName = this._suite.name;
610+
const testName = test.name;
611+
const startLabel = `${suiteName}.${testName}-start`;
612+
const syncEndLabel = `${suiteName}.${testName}-sync-end`;
613+
const asyncStartLabel = `${suiteName}.${testName}-async-start`;
614+
const asyncEndLabel = `${suiteName}.${testName}-async-end`;
613615

614616
let syncTime;
615617
let asyncStartTime;
@@ -644,28 +646,31 @@ export class SuiteRunner {
644646
performance.mark(asyncEndLabel);
645647
if (params.warmupBeforeSync)
646648
performance.measure("warmup", "warmup-start", "warmup-end");
647-
performance.measure(`${suite.name}.${test.name}-sync`, startLabel, syncEndLabel);
648-
performance.measure(`${suite.name}.${test.name}-async`, asyncStartLabel, asyncEndLabel);
649+
const suiteName = this._suite.name;
650+
const testName = test.name;
651+
performance.measure(`${suiteName}.${testName}-sync`, startLabel, syncEndLabel);
652+
performance.measure(`${suiteName}.${testName}-async`, asyncStartLabel, asyncEndLabel);
649653
};
650-
const report = () => this._recordTestResults(suite, test, syncTime, asyncTime);
654+
655+
const report = () => this._recordTestResults(test, syncTime, asyncTime);
651656
const invokerClass = TEST_INVOKER_LOOKUP[params.measurementMethod];
652657
const invoker = new invokerClass(runSync, measureAsync, report);
653658

654659
return invoker.start();
655660
}
656661

657-
async _recordTestResults(suite, test, syncTime, asyncTime) {
662+
async _recordTestResults(test, syncTime, asyncTime) {
658663
// Skip reporting updates for the warmup suite.
659-
if (suite === WarmupSuite)
664+
if (this._suite === WarmupSuite)
660665
return;
661-
662-
const suiteResults = this._measuredValues.tests[suite.name] || { tests: {}, total: 0 };
666+
const suiteName = this._suite.name;
667+
const suiteResults = this._measuredValues.tests[suiteName] || { tests: {}, total: 0 };
663668
const total = syncTime + asyncTime;
664-
this._measuredValues.tests[suite.name] = suiteResults;
669+
this._measuredValues.tests[suiteName] = suiteResults;
665670
suiteResults.tests[test.name] = { tests: { Sync: syncTime, Async: asyncTime }, total: total };
666671
suiteResults.total += total;
667672

668673
if (this._client?.didRunTest)
669-
await this._client.didRunTest(suite, test);
674+
await this._client.didRunTest(this._suite, test);
670675
}
671676
}

tests/benchmark-runner-tests.mjs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,11 @@ describe("BenchmarkRunner", () => {
188188
const suite = SUITES_FIXTURE[0];
189189

190190
before(async () => {
191+
runner._suite = suite;
191192
await runner._appendFrame();
192193
performanceMarkSpy = spy(window.performance, "mark");
193-
const suiteRunner = new SuiteRunner(runner._measuredValues, runner._frame, runner._page, runner._client, runner._suite);
194-
await suiteRunner._runTestAndRecordResults(suite, suite.tests[0]);
194+
const suiteRunner = new SuiteRunner(runner._measuredValues, runner._frame, runner._page, runner._client, suite);
195+
await suiteRunner._runTestAndRecordResults(suite.tests[0]);
195196
});
196197

197198
it("should run client pre and post hooks if present", () => {
@@ -225,8 +226,8 @@ describe("BenchmarkRunner", () => {
225226
stubPerformanceNowCalls(syncStart, syncEnd, asyncStart, asyncEnd);
226227

227228
// instantiate recorded test results
228-
const suiteRunner = new SuiteRunner(runner._measuredValues, runner._frame, runner._page, runner._client, runner._suite);
229-
await suiteRunner._runTestAndRecordResults(suite, suite.tests[0]);
229+
const suiteRunner = new SuiteRunner(runner._measuredValues, runner._frame, runner._page, runner._client, suite);
230+
await suiteRunner._runTestAndRecordResults(suite.tests[0]);
230231

231232
await runner._finalize();
232233
});

0 commit comments

Comments
 (0)