test_runner: align MockTimers timeout API#62820
Open
Han5991 wants to merge 1 commit intonodejs:mainfrom
Open
Conversation
Expose Timeout.close() and Timeout[Symbol.dispose]() from MockTimers. This keeps fake setTimeout() handles aligned with the public Timeout API so disposal-based patterns do not throw. Add targeted coverage for Timeout.close() and Timeout[Symbol.dispose]().
Collaborator
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #62820 +/- ##
==========================================
- Coverage 89.69% 89.66% -0.03%
==========================================
Files 706 706
Lines 218222 218235 +13
Branches 41768 41772 +4
==========================================
- Hits 195731 195683 -48
- Misses 14411 14455 +44
- Partials 8080 8097 +17
🚀 New features to boost your workflow:
|
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.
Summary
Align MockTimers timeout handles with the public Timeout API by exposing
close()and[Symbol.dispose]()on fakesetTimeout()results.Problem
When
test.mock.timers.enable()is active,setTimeout()returns a mock timeout handle that does not implementTimeout.close()orTimeout[Symbol.dispose](). That breaks disposal-based patterns such asDisposableStack.use(timeout).Root cause
MockTimers used its own
Timeoutwrapper with onlyref(),unref(),refresh(), andhasRef(), so the fake timeout handle diverged from the documented timeout API.Changes
Timeout.close()to the MockTimers timeout wrapperTimeout[Symbol.dispose]()to the MockTimers timeout wrapperValidation
out/Release/nodebefore the changepython3 tools/test.py test/parallel/test-runner-mock-timers.jsout/Release/nodenow reportsdispose function,close function, and allowsDisposableStack.use(timeout)Fixes: #62815