test(audit): fix flaky 412-retry backoff tests with setTimeout stub#298
Merged
Conversation
… 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 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>
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>
setTimeout stub
kptdobe
approved these changes
Jul 7, 2026
Collaborator
|
🎉 This PR is included in version 1.12.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After I merged #294 to main, the build on
mainfailed in the test phase, even after a re-run. https://github.com/adobe/da-admin/actions/runs/28807439450/job/85428064849This should make those tests fully deterministic to avoid this.
What changed
Groups the three
writeAuditEntry412-retry tests intest/storage/version/audit.test.jsunder a nesteddescribe('412 retry backoff', ...)with sharedbeforeEach/afterEachhooks that save/restoreglobalThis.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-jittersetTimeoutdelays — 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. StubbingsetTimeoutremoves 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.