Title: test_runner: `clearTimeout()` of a timer from a previous test's mock removes a timer of the current test · Issue #67593 · nodejs/node · GitHub
Open Graph Title: test_runner: `clearTimeout()` of a timer from a previous test's mock removes a timer of the current test · Issue #67593 · nodejs/node
X Title: test_runner: `clearTimeout()` of a timer from a previous test's mock removes a timer of the current test · Issue #67593 · nodejs/node
Description: Version v26.13.1 Platform Linux x64 Subsystem test_runner (mock timers) What steps will reproduce the bug? // stale-clear.test.mjs — run with: node --test stale-clear.test.mjs import { test } from 'node:test'; import assert from 'node:as...
Open Graph Description: Version v26.13.1 Platform Linux x64 Subsystem test_runner (mock timers) What steps will reproduce the bug? // stale-clear.test.mjs — run with: node --test stale-clear.test.mjs import { test } from ...
X Description: Version v26.13.1 Platform Linux x64 Subsystem test_runner (mock timers) What steps will reproduce the bug? // stale-clear.test.mjs — run with: node --test stale-clear.test.mjs import { test } from ...
Opengraph URL: https://github.com/nodejs/node/issues/67593
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"test_runner: `clearTimeout()` of a timer from a previous test's mock removes a timer of the current test","articleBody":"### Version\n\nv26.13.1\n\n### Platform\n\n```text\nLinux x64\n```\n\n### Subsystem\n\ntest_runner (mock timers)\n\n### What steps will reproduce the bug?\n\n```js\n// stale-clear.test.mjs — run with: node --test stale-clear.test.mjs\nimport { test } from 'node:test';\nimport assert from 'node:assert/strict';\n\nlet stale;\ntest('first test leaves a timer behind', (t) => {\n t.mock.timers.enable({ apis: ['setTimeout'] });\n stale = setTimeout(() => {}, 1000);\n});\n\ntest(\"a timer of the second test fires after the first test's timer is cleared\", (t) => {\n t.mock.timers.enable({ apis: ['setTimeout'] });\n let fired = false;\n setTimeout(() => { fired = true; }, 10);\n clearTimeout(stale); // a timer object from the previous test's mock\n t.mock.timers.runAll();\n assert.equal(fired, true);\n});\n```\n\n### How often does it reproduce? Is there a required condition?\n\nEvery run. The condition: a timer object made under one test's mock timers is cleared while a later test's mock timers are enabled.\n\n### What is the expected behavior? Why is that the expected behavior?\n\nThe second test passes: clearing a timer that is not in the current mock's queue should change nothing, as `clearTimeout()` of an unknown or already-fired timer does with the real timers.\n\n### What do you see instead?\n\n```text\nAssertionError [ERR_ASSERTION]: Expected values to be strictly equal:\n\nfalse !== true\n```\n\nThe second test's own timer never fires, not even with `runAll()`. Removing the `clearTimeout(stale)` line makes the test pass.\n\n### Additional information\n\n`MockTimers`' `#clearTimer` (`lib/internal/test_runner/mock/mock_timers.js`) removes by the timer's stored position without checking that the timer belongs to the current queue:\n\n```js\n#clearTimer(timer) {\n if (timer?.priorityQueuePosition !== undefined) {\n this.#executionQueue.removeAt(timer.priorityQueuePosition);\n```\n\nSo a stale timer's position removes whatever sits at that position in the new test's queue. This looks like the same family as #50365.\n\nTested on v26.13.1 only. We hit it in a real suite, where the stale clear most likely comes from the previous test's `fetch` cleaning up its connection after the next test has enabled its mock (not traced); we work around it by waiting 100 ms after closing the previous test's server.\n","author":{"url":"https://github.com/yufei-pan","@type":"Person","name":"yufei-pan"},"datePublished":"2026-11-18T19:34:05Z","url":"https://github.com/nodejs/node/issues/67593"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:31cb65e3-63d7-5554-d879-cc8e9e2d3aad |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9DDA:252852:3B8DDF:4DDD9D:6B0619A4 |
| html-safe-nonce | 88cf9f10c4e8d0555e8ddc381190a01c25c2a6367a6a3a13b3de18ad9e8c1b46 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RERBOjI1Mjg1MjozQjhEREY6NERERDlEOjZCMDYxOUE0IiwidmlzaXRvcl9pZCI6IjMyOTI1NjcwMDY1OTA5MzM0MTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5842a278f6614d177b54b9df820354d070a7f7b422ba9f0381ee13182d3bf604 |
| hovercard-subject-tag | issue:6475141147 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/67593/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c2209b2199df0d5710ee584d8148857d4f830cc785a8c10eb5dd05e388ff8a20/nodejs/node/issues/67593 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c2209b2199df0d5710ee584d8148857d4f830cc785a8c10eb5dd05e388ff8a20/nodejs/node/issues/67593 |
| og:image:alt | Version v26.13.1 Platform Linux x64 Subsystem test_runner (mock timers) What steps will reproduce the bug? // stale-clear.test.mjs — run with: node --test stale-clear.test.mjs import { test } from ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | yufei-pan |
| hostname | github.com |
| expected-hostname | github.com |
| None | 97d4714e567728e1f85f88b0cf68c89f0f8a3dc41e8869af7aeb8195ad990374 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 866f202ebf7ac5aff8f633417d9fd8a53818a977 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width