Skip to content

test(cleanup): stop part cleanup test from flaking when the Merge finishes early - #322

Merged
LouisHaftmann merged 1 commit into
devfrom
test/fix-flaky-part-cleanup-test
Nov 23, 2026
Merged

LouisHaftmann merged 1 commit into
devfrom
test/fix-flaky-part-cleanup-test

Conversation

@LouisHaftmann

Copy link
Copy Markdown
Collaborator

📝 Summary

CI on dev failed on part_cleanup_waits_for_an_active_parts_download (Postgres jobs, any storage; it also failed on the #319 and #321 PR runs). The server is correct. The test has a race.

The test opened two full downloads one after the other. When the Merge finished before the second download opened, that download read the merged object under a Storage Reader Lease, not a Part Reader Lease. Nothing then protected the Parts, so Part cleanup correctly deleted them, and the assertion saw 0 Parts.

Now the Parts reader opens first, as a ranged read. A ranged read always reads Parts and never starts a Merge, so it holds a Part Reader Lease on every backend.

 let storage = server.storage();
+let reading_parts = storage.download(&id, Some(0..)).await;  // ranged: always reads Parts
 let merging = storage.download(&id, None).await;
-let reading_parts = storage.download(&id, None).await;

✅ Verification

Forced the race by waiting 300 ms after the first download (so the Merge finishes) and after wait_for_ongoing_merges (so the first lease is released):

  • Before: sqlite and postgres: assertion left == right failed: parts are still being read, left: 0, right: 2
    After: sqlite and postgres: 1 passed

Gate: cargo +nightly fmt --check and cargo clippy --all-targets --locked are clean. cargo test passes on sqlite+filesystem and postgres+filesystem (84/84).

💥 Merge danger

Door: two-way

Blast Radius: tests-only

🤖 Generated with Claude Code

…ishes early

The second full download could open after the Merge completed, read the
merged object under a Storage lease, and leave the Parts unprotected.
Open the Parts reader first as a ranged read, which always reads Parts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Failed ❌

View logs ↗
51db083 2026-11-23T13:38:19.101Z View logs ↗

@LouisHaftmann
LouisHaftmann merged commit 875a6ec into dev Nov 23, 2026
28 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant