From e5f48b41f2bb4bb5d1a22c5edeb19ce93c390878 Mon Sep 17 00:00:00 2001 From: marcopiraccini Date: Sat, 19 Sep 2026 15:27:03 +0200 Subject: [PATCH] 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 --- test/wpt/test-timers.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/wpt/test-timers.js b/test/wpt/test-timers.js index efc2ee6e1ea6..ba84de258324 100644 --- a/test/wpt/test-timers.js +++ b/test/wpt/test-timers.js @@ -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();