Skip to content

Commit 612db6d

Browse files
panvaaduh95
authored andcommitted
test: deflake user timing WPT assertions
The fixed 20 ms tolerance in mark.any.js can fail when execution pauses between creating a mark and reading the clock. Adapt the test in memory to check the mark timestamp against readings before and after mark(). Keep the vendored fixture and subtest names unchanged. Apply script modifiers to worker entry scripts as well so the check covers both WPT globals, and remove the suite-wide flaky expectation. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: #66036 Backport-PR-URL: #66233 Fixes: #40449 Refs: #41203 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent a4effe6 commit 612db6d

3 files changed

Lines changed: 57 additions & 2 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const fixtures = require('../common/fixtures');
6+
const { spawnSync } = require('child_process');
7+
8+
if (process.env.NODE_TEST_WPT_MODIFIER_PROBE === '1') {
9+
const { WPTRunner } = require('../common/wpt');
10+
const runner = new WPTRunner('html/webappapis/atob');
11+
runner.setScriptModifier(common.mustCall((script) => {
12+
assert.strictEqual(script.filename,
13+
fixtures.path('wpt', 'html/webappapis/atob', 'base64.any.js'));
14+
script.filename += '.modified';
15+
script.code = `test(() => {
16+
assert_true(new Error().stack.includes(${JSON.stringify(`${script.filename}:`)}));
17+
}, 'modified script retains its filename');`;
18+
}));
19+
runner.runJsTests();
20+
} else {
21+
// eslint-disable-next-line no-unused-vars
22+
const { WPT_REPORT, ...env } = { ...process.env, NODE_TEST_WPT_MODIFIER_PROBE: '1' };
23+
const result = spawnSync(process.execPath, [__filename, 'base64.any.js'], {
24+
env,
25+
encoding: 'utf8',
26+
timeout: common.platformTimeout(10_000),
27+
});
28+
const { error, status, stdout, stderr } = result;
29+
assert.ifError(error);
30+
assert.strictEqual(status, 0, stdout + stderr);
31+
const results = stdout.split('\n').filter((line) => line.startsWith('[PASS]'));
32+
assert.deepStrictEqual(results, [
33+
'[PASS] modified script retains its filename',
34+
]);
35+
}

‎test/wpt/test-user-timing.js‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
11
'use strict';
22

3+
const assert = require('assert');
4+
const { basename } = require('path');
35
const { WPTRunner } = require('../common/wpt');
46

57
const runner = new WPTRunner('user-timing');
68

79
runner.pretendGlobalThisAs('Window');
810

11+
runner.setScriptModifier((script) => {
12+
if (basename(script.filename) !== 'mark.any.js') return;
13+
14+
// A scheduling pause between mark() and now() can exceed any fixed
15+
// tolerance. Check that the mark falls between the surrounding clock
16+
// readings instead, leaving the upstream fixture unchanged.
17+
// https://github.com/nodejs/node/issues/40449
18+
function replace(from, to) {
19+
assert(script.code.includes(from), `Unexpected contents of ${script.filename}`);
20+
script.code = script.code.replaceAll(from, to);
21+
}
22+
23+
replace('var expectedTimes = new Array();',
24+
'var beforeTimes = [];\nvar expectedTimes = new Array();');
25+
replace('self.performance.mark("mark");',
26+
'beforeTimes.push(self.performance.now());\n self.performance.mark("mark");');
27+
replace('assert_approx_equals(entries[index].startTime, expectedTimes[index], testThreshold);',
28+
'assert_between_inclusive(entries[index].startTime, beforeTimes[index], expectedTimes[index]);');
29+
});
30+
931
runner.runJsTests();

‎test/wpt/wpt.status‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ prefix wpt
55
# sample-test : PASS,FLAKY
66

77
[true] # This section applies to all platforms
8-
# https://github.com/nodejs/node/issues/40449
9-
test-user-timing: PASS,FLAKY
108

119
[$system==win32]
1210

0 commit comments

Comments
 (0)