Skip to content

test_runner: mocked timeout.refresh does not reschedule or reactivate a timeout #67577

Closed as not planned

Description

@archidoge0

Version

Node.js v24.22.2, v26.13.0 and v26.13.1

Platform

macOS 15.2, Darwin 24.2.0, arm64.

Subsystem

test_runner

What steps will reproduce the bug?

Save as repro.cjs:

const { mock } = require('node:test');
mock.timers.enable({ apis: ['setTimeout'] });

let fired = 0;
const t = setTimeout(() => { fired++; }, 100);

mock.timers.tick(60);
t.refresh();                 // should reschedule for t = 160
mock.timers.tick(60);        // t = 120
console.log('at 120ms:', fired);

mock.timers.tick(40);        // t = 160
console.log('at 160ms:', fired);

t.refresh();                 // should re-arm the fired timeout for t = 260
mock.timers.tick(100);       // t = 260
console.log('at 260ms:', fired);

mock.timers.reset();

Run:

node repro.cjs

How often does it reproduce? Is there a required condition?

Every run with setTimeout mocked, both before the timeout fires and after it has fired.

What is the expected behavior? Why is that the expected behavior?

at 120ms: 0
at 160ms: 1
at 260ms: 2

The timeout.refresh documentation says it resets the start time to the current time while retaining the duration, and reactivates a timer that has already fired. Refreshing the 100 ms timeout at 60 ms should move it to 160 ms; refreshing again at 160 ms should move it to 260 ms.

What do you see instead?

The listed versions produce:

at 120ms: 1
at 160ms: 1
at 260ms: 1

Additional information

The mock Timeout refresh method currently returns this without updating the execution queue. #62820 adds close/dispose support but does not implement refresh.

AI tools assisted with analysis and preparation of this report and its reproduction. A human has reviewed and confirmed the issue and verified that it is reproducible.

Credit: UCSB PLSE — https://ucsbplse.github.io/

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions