mock: make AbortSignal.timeout compatible with mock timers - #1
Open
DeveloperViraj wants to merge 2 commits into
Open
mock: make AbortSignal.timeout compatible with mock timers#1DeveloperViraj wants to merge 2 commits into
DeveloperViraj wants to merge 2 commits into
Conversation
PR-URL: nodejs#60705 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#60707 Refs: nodejs/admin#1005 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Richard Lau <richard.lau@ibm.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
DeveloperViraj
force-pushed
the
fix/mock-timers-abortsignal-timeout
branch
from
November 15, 2025 20:43
c30dce3 to
735ee27
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for AbortSignal.timeout() to the MockTimers implementation used by the Node.js test runner.
By mocking AbortSignal.timeout(), MockTimers can now control and simulate abort signals driven by timeouts, making it possible to write fully deterministic tests for code that depends on timed abort behavior.
Key changes
Added AbortSignal.timeout to the list of supported mocked timer APIs.
Implemented a mock version of AbortSignal.timeout() that schedules the abort using MockTimers’ internal queue.
Ensures the original AbortSignal.timeout implementation is restored when MockTimers are reset.
Added a dedicated test to verify:
the signal is initially not aborted,
the signal remains un-aborted until just before the timeout,
the signal aborts exactly at the expected time using tick().
Tests
A new test has been added:
test/parallel/test-mock-timers-abortsignal-timeout.js
This test validates the expected behavior of mocked timeout-based abort signals.