Skip to content

test(audit): fix flaky 412-retry backoff tests with setTimeout stub#298

Merged
kptdobe merged 5 commits into
mainfrom
fix/audit-test-flaky-timeout
Jul 7, 2026
Merged

test(audit): fix flaky 412-retry backoff tests with setTimeout stub#298
kptdobe merged 5 commits into
mainfrom
fix/audit-test-flaky-timeout

Conversation

@shsteimer

@shsteimer shsteimer commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

After I merged #294 to main, the build on main failed in the test phase, even after a re-run. https://github.com/adobe/da-admin/actions/runs/28807439450/job/85428064849

This should make those tests fully deterministic to avoid this.

What changed

Groups the three writeAuditEntry 412-retry tests in test/storage/version/audit.test.js under a nested describe('412 retry backoff', ...) with shared beforeEach/afterEach hooks that save/restore globalThis.setTimeout. Each test installs its own replacement (fire-immediately, or delay-capturing for the jitter-value assertions). No production code changed.

Why

writeAuditEntry's retry backoff (src/storage/version/audit.js) sleeps between attempts using real exponential-jitter setTimeout delays — worst case ~3050ms across 6 retries. One of these tests used real timers for that full retry chain, racing mocha's 2000ms default test timeout and intermittently failing CI. Stubbing setTimeout removes the real wait entirely, making the test deterministic. The other two tests in the same block had the same real-timer exposure (one already stubbed it independently, one didn't), so they're consolidated here rather than leaving three near-identical stub/restore blocks scattered through the file.

… flake

writeAuditEntry retries PUT 412s with real exponential-jitter delays
(worst case ~3050ms), which raced mocha's 2000ms default test timeout
and intermittently failed CI. Stub setTimeout to fire immediately, same
pattern already used by the neighboring backoff-assertion test.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…imeout hooks

The three 412-retry tests each stubbed/restored setTimeout independently,
duplicating the same save/restore boilerplate and risking future tests
forgetting to restore it. Group them under a nested describe('412 retry
backoff') with beforeEach/afterEach owning save/restore of the setTimeout
reference; each test still installs whatever replacement behavior it
needs (plain fire-immediately vs. delay-capturing for the jitter
assertions). Also removes real-timer usage from 'succeeds on the 5th
attempt after four 412s', which previously took ~500-700ms per run.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@shsteimer shsteimer changed the title fix(test): stub setTimeout in audit 412-retry test to prevent timeout flake test(audit): fix flaky 412-retry timeout, consolidate retry-backoff stubbing Jul 6, 2026
@shsteimer shsteimer changed the title test(audit): fix flaky 412-retry timeout, consolidate retry-backoff stubbing test(audit): stub setTimeout for 412-retry backoff tests Jul 6, 2026
shsteimer and others added 3 commits July 6, 2026 10:06
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@shsteimer shsteimer requested review from kptdobe and tripodsan July 6, 2026 17:14
@shsteimer shsteimer marked this pull request as ready for review July 6, 2026 17:14
@shsteimer shsteimer changed the title test(audit): stub setTimeout for 412-retry backoff tests test(audit): fix flaky 412-retry backoff tests with setTimeout stub Jul 6, 2026
@kptdobe kptdobe merged commit d10c296 into main Jul 7, 2026
6 checks passed
@kptdobe kptdobe deleted the fix/audit-test-flaky-timeout branch July 7, 2026 06:59
@adobe-bot

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 1.12.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants