Skip to content

Fix flaky threshold test in extraction-manager #384

@rjroy

Description

@rjroy

Problem

The test needsCatchUp edge cases > handles exactly at threshold is flaky and failed in CI.

Root Cause

The test calculates exactlyAtThreshold using Date.now(), then needsCatchUp() internally calls Date.now() again. If even 1ms passes between those calls, the elapsed time exceeds the threshold and the test fails.

const exactlyAtThreshold = new Date(Date.now() - DEFAULT_CATCHUP_THRESHOLD_MS).toISOString();
// ... time passes ...
expect(needsCatchUp(state)).toBe(false);  // needsCatchUp calls Date.now() again

Fix

Inject a clock/time provider into needsCatchUp() so tests can control time deterministically.

Acceptance Criteria

  • Test passes reliably (no timing dependency)
  • needsCatchUp() accepts optional now parameter or clock injection
  • Existing behavior unchanged when no clock provided

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions