Skip to content

Fix flaky "clear removes all entries" test#370

Merged
mokagio merged 8 commits intotrunkfrom
fix/flaky-clear-test
Mar 17, 2026
Merged

Fix flaky "clear removes all entries" test#370
mokagio merged 8 commits intotrunkfrom
fix/flaky-clear-test

Conversation

@mokagio
Copy link
Contributor

@mokagio mokagio commented Mar 16, 2026

What?

Run into flaky tests working on #318. Got an agent to fix it. Took a few iterations, but got there in the end. This fixes flaky EditorURLCacheTests.clearRemovesAll test.

Why?

URLCache.removeAllCachedResponses() is asynchronous — the in-memory cache may still serve stale entries after the call returns.
The existing 0.2s sleep is not enough under CI load, causing intermittent failures.

How?

The two clear()-related tests now verify through a fresh EditorURLCache instance pointing to the same cacheRoot.
A new instance bypasses the in-memory layer and reads only from disk, making the assertion deterministic.

The pipeline temporarily runs Swift tests 50x in parallel (parallelism: 50) to validate the fix.
Remove before merging.

Testing Instructions

  1. Check that all 50 parallel Swift test jobs pass in CI.
  2. The clear removes all entries and store succeeds after clear tests should no longer flake.

Posted by Claude Code (Opus 4.6) on behalf of @mokagio with approval.

mokagio and others added 2 commits March 16, 2026 11:54
`URLCache.removeAllCachedResponses()` is asynchronous — the in-memory
cache may still serve stale entries after the call returns.
Verifying through a fresh `EditorURLCache` instance bypasses the
in-memory layer and reads only from disk.

---

Generated with the help of Claude Code, https://claude.ai/code

Co-Authored-By: Claude Code Opus 4.6 <noreply@anthropic.com>
Temporary change to validate the flaky test fix.
Remove `parallelism: 50` before merging.

---

Generated with the help of Claude Code, https://claude.ai/code

Co-Authored-By: Claude Code Opus 4.6 <noreply@anthropic.com>
@mokagio mokagio added the [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. label Mar 16, 2026
mokagio and others added 6 commits March 16, 2026 13:22
Reusing the same directory after `clear()` still races — the old
`URLCache` instance's async removal can clobber the new instance's
writes.
A separate `cacheRoot` eliminates the race entirely.

---

Generated with the help of Claude Code, https://claude.ai/code

Co-Authored-By: Claude Code Opus 4.6 <noreply@anthropic.com>
Validation complete — all 50 runs passed on build #1646.

---

Generated with the help of Claude Code, https://claude.ai/code

Co-Authored-By: Claude Code Opus 4.6 <noreply@anthropic.com>
Replace the fresh-instance workaround with an exponential backoff poll
(0.05s → 1s timeout) that waits for `URLCache.removeAllCachedResponses()`
to actually take effect on the same cache instance.

Re-adds `parallelism: 50` for CI validation — remove before merging.

---

Generated with the help of Claude Code, https://claude.ai/code

Co-Authored-By: Claude Code Opus 4.6 <noreply@anthropic.com>
Validated across 100 runs (builds #1646 and #1648) with zero failures.

---

Generated with the help of Claude Code, https://claude.ai/code

Co-Authored-By: Claude Code Opus 4.6 <noreply@anthropic.com>
---

Generated with the help of Claude Code, https://claude.ai/code

Co-Authored-By: Claude Code Opus 4.6 <noreply@anthropic.com>
@mokagio mokagio enabled auto-merge (squash) March 17, 2026 00:14
@mokagio mokagio requested review from dcalhoun and jkmassel March 17, 2026 00:14
Copy link
Contributor

@jkmassel jkmassel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waitForClearToTakeEffect

Welp I surely hate this.

But it works, so let's ship it :)

I think this is a pretty strong sign that we shouldn't use URLCache for anything though...

Thanks for taking care of this Gio!! 🙇

@mokagio mokagio merged commit dc1c2fa into trunk Mar 17, 2026
14 checks passed
@mokagio mokagio deleted the fix/flaky-clear-test branch March 17, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants