test: deflake user timing WPT assertions · nodejs/node@612db6d · GitHub
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

‎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

0 commit comments

Comments
 (0)