fix(tests): tolerate a source file vanishing during a recursive copy#36189
Open
crowlbot wants to merge 1 commit into
Open
fix(tests): tolerate a source file vanishing during a recursive copy#36189crowlbot wants to merge 1 commit into
crowlbot wants to merge 1 commit into
Conversation
`PathRef::copy_to_recursive_with_exclusions` lists a directory and then copies each entry. When specs run in parallel, a concurrent process can regenerate a gitignored cache directory (e.g. `.deno/npm-compat`, which leaks into a spec's source tree) and remove a file after `read_dir` listed it but before the copy. `std::fs::copy` then fails with `NotFound` and the `.unwrap()` panicked, failing an unrelated test (#36184). Add `PathRef::copy_if_exists`, which treats a missing source as a no-op, and use it in the recursive copy. Because the entry was just returned by `read_dir`, a `NotFound` at copy time is unambiguously a concurrent removal, so skipping it is correct; other copy errors still panic.
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.
What
specs::npm::pkg_json_imports::compileintermittently panics in the test harness:PathRef::copy_to_recursive_with_exclusionslists a directory withread_dirand then copies each entry viaPathRef::copy, which.unwrap()s thestd::fs::copyresult.Why
.deno/npm-compatis a gitignored, generated cache directory (cli/tools/installer/npm_compat.rs) that ends up inside a spec's source tree as a side effect of running the spec. Specs (and the test cases within a spec) run in parallel, all copying that source tree into per-test temp dirs. When one test's recursive copy is mid-flight and another concurrently regenerates.deno/npm-compat, a file thatread_dirjust listed can be removed before the copy runs —std::fs::copyreturnsNotFound, and the.unwrap()panics, failing the test.Fix
Add
PathRef::copy_if_exists, which treats a missing source as a no-op (returnsfalse) instead of panicking, and use it in the recursive copy. Because the entry was just returned byread_dir, aNotFoundat copy time is unambiguously a concurrent removal rather than a statically missing file, so skipping it is correct. All other copy errors still panic, preserving diagnostics.This is the same class of fix as #36138 (make the shared test infrastructure resilient to a benign parallel-execution race). A deeper follow-up would be to stop the gitignored
.deno/npm-compatcache from leaking into the shared spec source tree in the first place, but that's a larger change; this removes the panic.I can't reproduce the linux-aarch64 timing race locally, but the change turns the racy removal into a no-op instead of an
unwrappanic.cargo check -p test_utilpasses.Closes #36184