Skip to content

test_runner: align MockTimers timeout API#62820

Open
Han5991 wants to merge 1 commit intonodejs:mainfrom
Han5991:fix/62815-mocktimers-timeout-api
Open

test_runner: align MockTimers timeout API#62820
Han5991 wants to merge 1 commit intonodejs:mainfrom
Han5991:fix/62815-mocktimers-timeout-api

Conversation

@Han5991
Copy link
Copy Markdown
Contributor

@Han5991 Han5991 commented Apr 19, 2026

Summary

Align MockTimers timeout handles with the public Timeout API by exposing close() and [Symbol.dispose]() on fake setTimeout() results.

Problem

When test.mock.timers.enable() is active, setTimeout() returns a mock timeout handle that does not implement Timeout.close() or Timeout[Symbol.dispose](). That breaks disposal-based patterns such as DisposableStack.use(timeout).

Root cause

MockTimers used its own Timeout wrapper with only ref(), unref(), refresh(), and hasRef(), so the fake timeout handle diverged from the documented timeout API.

Changes

  • add Timeout.close() to the MockTimers timeout wrapper
  • add Timeout[Symbol.dispose]() to the MockTimers timeout wrapper
  • route both methods through the existing timer clear path
  • add targeted coverage for both disposal entry points

Validation

  • reproduced the issue with out/Release/node before the change
  • python3 tools/test.py test/parallel/test-runner-mock-timers.js
  • verified the built out/Release/node now reports dispose function, close function, and allows DisposableStack.use(timeout)

Fixes: #62815

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]().
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Apr 19, 2026
@Han5991 Han5991 marked this pull request as ready for review April 19, 2026 06:15
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.66%. Comparing base (58a8e1d) to head (eea8f04).

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     
Files with missing lines Coverage Δ
lib/internal/test_runner/mock/mock_timers.js 98.71% <100.00%> (+0.02%) ⬆️

... and 34 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MockTimers does not implement Timeout API correctl

2 participants