Test runs remove their data directory (#8) #10

Closed
mercurius wants to merge 0 commits from mercurius/8-test-tmp-dirs into main
Member

Purpose (fix): a test run leaves no data directory in the system temp dir.

Refs #8, Refs #4

What changes

config/runtime.exs (:test branch only) registers System.at_exit(fn _ -> File.rm_rf(dir) end) for the exact directory it made for this run. It globs nothing, and a non-test run never registers it.

It lives here, not in each app's test_helper: the umbrella's mix test runs every app's suite in one VM, which evaluates this file once. A per-app after_suite would delete the directory under the next app's open stores. The runs below show after_suite callbacks piling up across the apps.

Proof (msi00, ci image)

Run rc dirs left
umbrella 0 0
mcl_bookclub_phoenix alone 0 0
umbrella with an injected failing test 2 (unchanged) 0
mutant: hook removed 0 1

Format, compile --warnings-as-errors and credo --strict are clean.

Purpose (fix): a test run leaves no data directory in the system temp dir. Refs #8, Refs #4 ## What changes `config/runtime.exs` (`:test` branch only) registers `System.at_exit(fn _ -> File.rm_rf(dir) end)` for the exact directory it made for this run. It globs nothing, and a non-test run never registers it. It lives here, not in each app's test_helper: the umbrella's `mix test` runs every app's suite in one VM, which evaluates this file once. A per-app `after_suite` would delete the directory under the next app's open stores. The runs below show `after_suite` callbacks piling up across the apps. ## Proof (msi00, ci image) | Run | rc | dirs left | |---|---|---| | umbrella | 0 | 0 | | mcl_bookclub_phoenix alone | 0 | 0 | | umbrella with an injected failing test | 2 (unchanged) | 0 | | mutant: hook removed | 0 | 1 | Format, compile `--warnings-as-errors` and credo `--strict` are clean.
config/runtime.exs gives every :test run a fresh
mcl_bookclub_test_<unique> dir under System.tmp_dir!() and nothing
removed it. It now registers System.at_exit/1 for that exact dir, so
it goes once the last suite in the VM is done, pass or fail, without
touching the exit code. A per-app ExUnit.after_suite would remove it
under the next app's open stores in the umbrella run.

Refs macula-services/mcl-bookclub-phoenix#8
Refs macula-services/mcl-bookclub-phoenix#4
Merge remote-tracking branch 'origin/main' into mercurius/8-test-tmp-dirs
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 2s
c4 model / c4-model (pull_request) Successful in 0s
ci / gates (OTP 28.4.3 / Elixir 1.18.4) (pull_request) Successful in 10m22s
9a60c0819a
The test run's data dir gets a random name, not System.unique_integer
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 3s
c4 model / c4-model (pull_request) Successful in 0s
ci / gates (OTP 28.4.3 / Elixir 1.18.4) (pull_request) Successful in 6m44s
6700f1f9ae
unique_integer is unique only inside one VM and starts near the same value
in every fresh one, so two test runs at once could share a dir, and the
at_exit rm_rf of the first to exit would delete the other's live stores
(review r1 of macula-services/mcl-bookclub-phoenix#8).
Merge remote-tracking branch 'origin/main' into mercurius/8-test-tmp-dirs
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 3s
c4 model / c4-model (pull_request) Successful in 0s
ci / gates (OTP 28.4.3 / Elixir 1.18.4) (pull_request) Successful in 6m46s
c4 model / c4-model-1 (push) Successful in 4s
c4 model / c4-model (push) Successful in 0s
ci / gates (OTP 28.4.3 / Elixir 1.18.4) (push) Successful in 7m14s
e9cc237263
Member

Landed by fast-forward: phoenix main is e9cc237263, this PR's head (PASS r=1, CI 6136 + 6137). Closed rather than merged: this repository does not allow the manually-merged style.

Landed by fast-forward: phoenix main is e9cc23726381f8b4e707f6b70e9d418ce0a5050f, this PR's head (PASS r=1, CI 6136 + 6137). Closed rather than merged: this repository does not allow the manually-merged style.
terra closed this pull request 2026-12-01 06:00:20 +00:00
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 3s
c4 model / c4-model (pull_request) Successful in 0s
ci / gates (OTP 28.4.3 / Elixir 1.18.4) (pull_request) Successful in 6m46s
c4 model / c4-model-1 (push) Successful in 4s
c4 model / c4-model (push) Successful in 0s
ci / gates (OTP 28.4.3 / Elixir 1.18.4) (push) Successful in 7m14s

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
macula-services/mcl-bookclub-phoenix!10
No description provided.