test_runner: run the longest timer in runAll() by spokodev · Pull Request #66896 · nodejs/node · GitHub
Skip to content

test_runner: run the longest timer in runAll() - #66896

Open
spokodev wants to merge 1 commit into
nodejs:mainfrom
spokodev:test-runner-runall-longest-timer
Open

spokodev wants to merge 1 commit into
nodejs:mainfrom
spokodev:test-runner-runall-longest-timer

Conversation

@spokodev

Copy link
Copy Markdown

What?

Fixes t.mock.timers.runAll() skipping the longest timer when it's scheduled before shorter ones.

For example, timers scheduled at 9999, 8888, and 8888 ms only execute the two shorter callbacks.

Why?

PriorityQueue#peekBottom() returns the last element of the heap, which isn't necessarily the largest.

How?

Update peekBottom() to find the largest element among the heap's leaves.

Added a regression test based on the existing documentation example. test/parallel/test-runner-mock-timers.js passes (62/62) with the fix, and the new test fails without it. I ran it against a nightly build with the changed files loaded, not a full local build. ESLint passes on the changed files.

AI assistance was used to investigate and implement the fix. I reviewed the changes and test results.

PriorityQueue#peekBottom() returned the last slot of the heap, which is
not necessarily the largest element, so MockTimers#runAll() could stop
before the timer that fires last. Scan the leaves of the heap for the
largest element instead.

Assisted-by: a closed-source coding agent
Signed-off-by: Yarchik <spoko.dev@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Oct 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agentscan:community-flagged needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants