test: deflake long timer WPTs

type-long-settimeout.any.js and type-long-setinterval.any.js arm
setTimeout(assert_unreached, 100) as a guard. Under load it can fire
after done(), and the resulting uncaught exception can reach the WPT
runner before the completion message, failing the spec.

Use a script modifier to clear the guard timer from a completion
callback, for these two fixtures only. The guard still fails the test
when done() is never called.

Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/63106
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
This commit is contained in:
Marco authored and Antoine du Hamel committed 2026-09-27 17:25:56 +02:00
1 parent a1bfb6fcda
commit fb9aba67dd
1 file changed
+15
+15
View File
@@ -1,7 +1,22 @@
'use strict';
const assert = require('assert');
const { basename } = require('path');
const { WPTRunner } = require('../common/wpt');
const runner = new WPTRunner('html/webappapis/timers', { concurrency: 1 });
runner.setScriptModifier((script) => {
if (!['type-long-settimeout.any.js', 'type-long-setinterval.any.js']
.includes(basename(script.filename))) return;
// Cancel the failure timer when the test completes so it cannot throw
// while the runner is still processing the completion message.
const failureTimer = 'setTimeout(assert_unreached, 100);';
assert(script.code.includes(failureTimer), `Unexpected contents of ${script.filename}`);
script.code = script.code.replace(failureTimer,
'const failureTimer = setTimeout(assert_unreached, 100);\n' +
'add_completion_callback(() => clearTimeout(failureTimer));');
});
runner.runJsTests();