Skip to content

test: keep TMPDIR outside the directory a test deletes - #12

Merged
oonid merged 1 commit into
mainfrom
fix/test-tmpdir-race
Oct 17, 2026
Merged

oonid merged 1 commit into
mainfrom
fix/test-tmpdir-race

Conversation

@oonid

@oonid oonid commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

main's CI failed after #11 in a test unrelated to it: shared::tests::read_helpers_report_expected_access (assertion failed: can_read_file(...)).

Cause. build_proot_args_non_isolated_includes_prefix_and_mounts set TMPDIR to <its temp dir>/cache and then removed that temp dir. Tests build scratch paths with std::env::temp_dir(), which reads TMPDIR, and 25 of them do not take the env lock. One that ran in that window created its files inside the doomed tree and lost them. Reproduced locally in 1 of 40 cargo test --lib runs on main.

Fix. Both tests that set TMPDIR now set it to the value temp_dir() already returns, so they still check that TMPDIR wins over the $APP_PREFIX/tmp fallback while no other test sees a different temp dir, and they restore the caller's TMPDIR instead of removing it. (build_proot_runtime_env_prefers_tmpdir_when_set used /tmp/custom-cache; tests running in its window created directories there.)

Same class, checked. Of the other env vars tests set, APP_PREFIX is set by 27 tests; the 15 unlocked tests that reach env-reading code only assert values that do not depend on it (early validation errors, paths from /proc/self/exe, the fixed DNS fallback, LANG), so TMPDIR was the only path to this failure.

Verification. 0 failures in 240 local cargo test --lib runs with TMPDIR unset and 60 with it set to a custom dir; cargo test 169 passed; fmt clean, clippy unchanged (21 pre-existing). Re-running main's failed job passed, as expected for a race.

build_proot_args_non_isolated_includes_prefix_and_mounts pointed TMPDIR
at <its temp dir>/cache and then removed that temp dir. The other tests
build their scratch paths with std::env::temp_dir(), which reads TMPDIR,
and 25 of them do not take the env lock. One that ran in that window
created its files inside the doomed tree and lost them:
read_helpers_report_expected_access failed with
`assertion failed: can_read_file(...)` on main's CI after #11, and in
1 of 40 local runs.

Both tests that set TMPDIR now set it to the value temp_dir() already
returns, so they still check that TMPDIR wins over the
$APP_PREFIX/tmp fallback while no other test sees a different temp
dir (build_proot_runtime_env_prefers_tmpdir_when_set used
/tmp/custom-cache, where tests running in its window left
directories), and they restore the caller's TMPDIR instead of
removing it. 0 failures in 240 local runs with TMPDIR unset and 60
with it set.
@oonid
oonid force-pushed the fix/test-tmpdir-race branch from f853b11 to cc0c7c3 Compare October 17, 2026 12:30
@oonid
oonid merged commit 86d9e93 into main Oct 17, 2026
1 check passed
@oonid
oonid deleted the fix/test-tmpdir-race branch October 17, 2026 14:38
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