test: media tests flake under parallel runs — staging dir is shared across #[sqlx::test]s #170
Labels
No labels
kind
bug
kind
enhancement
wayfinder
grilling
wayfinder
map
wayfinder
prototype
wayfinder
research
wayfinder
task
workflow
needs-info
workflow
needs-triage
workflow
ready-for-agent
workflow
ready-for-human
workflow
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
rosa/vernier#170
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Two media integration tests in
crates/server/tests/app_test.rsfail intermittently when the suite runs with the default parallel test harness, but pass reliably single-threaded.Affected tests
web_editor_uploads_then_removes_a_photo— afterrun_optimize_media, the page still renders "This photo is still being processed…" and the assertionassert_text_contains("u-photo")(app_test.rs:979) fails.undecodable_upload_fails_the_media_and_deletes_the_staged_original—an undecodable image is a terminal failure, got Ok(())(app_test.rs:1137).Evidence
cargo test -p vernier-server(default parallelism): one or both fail, non-deterministically.cargo test -p vernier-server --test app_test -- --test-threads=1: all 59 pass.So it is a cross-test interference race, not a logic bug in either test.
Suspected root cause
staging_dir()(crates/infra/src/staging.rs:117) derives the media-staging directory as a sibling of the database file:<db-parent>/media-staging. The test harness builds staging from the test pool's filename:(
crates/server/tests/common/mod.rs:110)Under
#[sqlx::test]the per-test SQLite databases share a parent directory, so every test resolves to the samemedia-stagingfolder. Staged originals are then keyed only byMediaIdin one shared directory, and tests that scan or delete staged files step on each other. In particularreconciler_sweeps_an_orphaned_staged_originaldeletes staged originals it considers orphaned; running concurrently it can remove another test's staged original before that test's optimize job reads it — which matches the "still being processed" / "got Ok(())" symptoms (the optimize job finds no bytes to work from).Suggested fix
Give each test its own staging directory instead of one derived from a shared temp parent — e.g. stage under a unique per-test subdirectory (keyed off the unique DB filename, a
tempfile::TempDir, or the operator sequence already used incommon/mod.rs), so no two tests share amedia-stagingfolder. The production derivation instaging_dir()is correct and should stay as-is; only the test harness needs isolation.