Guides · choose the right test control

API time, application timers and test clocks

A report is ready at the API, but the app still says Processing. Separate the dependency’s clock, the app’s time read and the timer that sends the next request.

Timing debugger

Why does the report still say Processing?

Move the dependency’s clock and the app’s mocked Date, then run the scheduled poll. Try polling early to see the difference.

Dispatch DeskWest Coast AK
Shipments ReportsTeam

Operations

Reports

17–23 Jun
Weekly dispatch summary

Requested by Alex Kim · 09:00

Processing
Dispatch performancePreparing export
M
T
W
T
F
S
S
Completed—
On time—
Routes—
The app is waiting for its next status check.
App Date read
09:00:00
Polls since page load
0

Test controls

Dependency clock+0s · report processing
App wall-time read+0s · mocked Date
App scheduler+0s · callback queued

Event log

  1. App
    GET /reports/weekly · 202

    Processing. Next poll queued for +30s.

Authored clock model running in this page. The dependency clock, mocked Date and poll timer are independent controls in this sample.

GET /reports/weekly · 202. Processing. Next poll queued for +30s.

Three boundaries, each with its own control

These are control boundaries, not three physically independent clocks. Your app’s normal Date reads usually reflect host wall time; a test can substitute those reads without changing the host.

API environment

What the dependency serves

A resource read changes from valid to expired.

Control
A supported API scenario’s explicit time advance
Boundary
Does not run the client’s pending refresh callback

Application reads & timers

What your code considers due

A local expiry check, timeout or scheduled refresh.

Control
An injected clock or selected test-runner fake APIs
Boundary
A mocked Date and a timer queue can need different controls

Host & external time

What remains outside those controls

The operating system, another process or a real provider.

Control
A test seam in that component or a suitable isolated test
Boundary
An in-process clock substitute does not change the OS
Trace which reads and timers each control replaces. API-time advances leave the application scheduler and host clock outside their scope.

Choose the control from the decision

Trace the check that produces the result you care about. A timestamp in an API response is data; your app may still make the expiry decision using its own time source.

Does the API report whether a resource is expired?
Prepare that API case. Use supported API-time controls when its state must evolve; assert the response and your client’s handling.
Does your code compare a timestamp with its own current time?
Inject the time source or fake the app’s Date reads. Test the exact boundary in that code.
Are you waiting for backoff, polling or a refresh callback?
Control the application scheduler and its deadline source. Observe which callbacks and requests actually run.
Does a database, worker or external service decide the time?
Control that component separately. A clock double in the client process will not reach it.

Copy this into the test plan

CLOCK-CONTROL WORKSHEET
The decision I need to test: ______________________________
The component that makes that decision: ___________________
Its time source / scheduler: ______________________________
The input that defines expiry or the wait: ________________
The control I will move: __________________________________
What must remain unchanged: _______________________________
Expected before / at / after the boundary: ________________
State and pending work to clear before repeating: _________

Apply the distinction to an expiring resource

The expiring-resource test contains the complete authored before, at and after expiry plan. It uses a disposable resource with a 60-second API lifetime while holding the app’s separate 30-second refresh callback pending, then checks what changes when the scheduler moves.

Keep both reset boundaries in the plan. Restoring the API episode does not clear the app’s cached resource ID, pending timers or observable state. Create again and use the returned ID when repeating.

Change the expiry owner, change the test. If your app instead compares a timestamp or a JWT expiry claim with its own current time, keep the API response fixed and move the app’s time source. The episode-resource contract does not validate arbitrary bearer tokens or apply a provider’s authentication policy.

When an ordinary test clock is enough

For an app-local timestamp check, pass a time source into the code or use your existing test runner’s mocked Date. For a scheduled wait, use its timer controls and observe callbacks. A fixed HTTP response is often enough for either test.

Changing mocked system time and running scheduled work are different operations. In Vitest, setting system time does not fire timers. In Node MockTimers, setting time does not execute timers, while ticking runs due mocked timers and can advance mocked Date too. Select the APIs your case needs.

Restore the real APIs and clear pending work after each test. For a worker, database or provider outside that process, use a control supported by that component or a separate integration case.

Retries add an attempt limit and total deadline. Keep those under the client’s scheduler and elapsed-time source; an API-time advance does not make the next attempt eligible. The retry-testing guide supplies assertions for those bounds.

Use API-time controls when the dependency owns the change

Time Chamber advances an episode’s simulated API time explicitly. Its supported resource lifetime changes what a resource read returns; it does not speed up app timers, change the host clock or interpret arbitrary token contents.

Check the documented create/read and lifetime contract before choosing it for your case. If that fits, the quickstart is the supported setup path.

For an inspectable clock boundary, the rate-limit walkthrough uses saved synthetic runs observed on October 18, 2026. Its player shows a recorded API-time advance followed by a separate client retry. That evidence concerns its saved scenario; the linked resource-expiry exercise is an authored test plan.

Resources

Continue with the control your case needs

Check the API-time fit

Read the supported episode-created resource contract and the clock’s operating boundaries.

Read the API time reference

Test the client’s wait and stop

Define attempts, eligible retry time and the deadline in your own client test.

Read the retry guide

Prepare an HTTP case when it fits

Install the supported stack, configure one safe dependency and confirm replay.

Follow the quickstart

Choose the clock before choosing the setup.

Use your existing test clock for application logic. When the dependency owns the time-sensitive state, check the supported API-time workflow.

Explore API-time controls