Skip to content

mock: make AbortSignal.timeout compatible with mock timers - #1

Open
DeveloperViraj wants to merge 2 commits into
mainfrom
fix/mock-timers-abortsignal-timeout
Open

mock: make AbortSignal.timeout compatible with mock timers#1
DeveloperViraj wants to merge 2 commits into
mainfrom
fix/mock-timers-abortsignal-timeout

Conversation

@DeveloperViraj

Copy link
Copy Markdown
Owner

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.

nodejs-github-bot and others added 2 commits November 15, 2025 16:15
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
DeveloperViraj force-pushed the fix/mock-timers-abortsignal-timeout branch from c30dce3 to 735ee27 Compare November 15, 2025 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants