Skip to content

Flaky test: scheduler backoff test fails during 07:59 HST cron-boundary minute #345

@mgoldsborough

Description

@mgoldsborough

Summary

test/unit/bundles/automations/scheduler.test.ts → "Scheduler — backoff respects natural interval > cron automation with 1 error delays to next cron occurrence, not 30s" is time-dependent and flakes during a one-minute wall-clock window.

The test sets a daily 0 8 * * * (Pacific/Honolulu) cron and asserts that after one failure the next run is the natural cron occurrence (hours away) rather than the 30s error backoff:

// Next 8am is at least 1 hour away (unless test runs exactly at 7:59am HST)
expect(nextRunMs - Date.now()).toBeGreaterThan(60_000);

When the suite runs during 07:59 HST, the next 8am occurrence is <60s away, the 30s backoff wins, and the assertion fails. This is self-documented in the test comment.

Evidence

Observed in CI: a run at 17:59:33 UTC (= 07:59:33 HST) failed only this test; an immediate re-run at a different minute passed. Reproduces deterministically by running the test within the 07:59 HST minute.

Fix options

  • Inject/mock the clock (freeze Date.now() to a fixed non-boundary instant) so the assertion is time-independent — preferred.
  • Or compute the threshold from the actual next cron occurrence instead of a hard-coded 60_000.

Priority

P3 — flaky test, no production impact.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions