Repository navigation
tests: a test process drops the databases it created - #313
Merged
Merged
Conversation
Every spawned test app creates its own database (~11 MB with the
migrations) and nothing dropped them. A full CI run filled the runner's
disk until Postgres panicked ("could not write to file pg_wal/...: No
space left on device") and the last few hundred tests failed with
"Failed to start test app", on every branch.
configure_database (integration and BDD harnesses) now registers each
database it creates, and an atexit handler drops them all with
DROP DATABASE ... WITH (FORCE) when the process exits. Most apps live in
a static shared by a test file, so a Rust Drop would never run; process
exit is the end of each test under nextest and of each binary under
cargo test. The drop runs on a fresh thread: at exit the main thread's
thread-locals, which tokio needs, are gone.
Regression test: tests/test_databases_are_dropped.rs runs a child test
process that spawns an app, then checks its database is gone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem. Every spawned test app creates its own database (about 11 MB with the migrations), and nothing drops them. A full CI run fills the runner's disk until Postgres crashes:
The last few hundred tests then fail with
Failed to start test app(andfailed to lookup address informationforpostgres). Which tests turn red depends only on which ran after the crash. This hits every branch, includingmain(9b165e7), #310, #311 and #312. Re-runs do not help. Locallystacker-test-pghad accumulated 4450 such databases, 47 GB.Change (test code only)
tests/common/test_databases.rs, included by both harnesses the same way asvault_kv_mock.rs.configure_databaseintests/common/mod.rsandtests/steps/common.rsregisters each database right afterCREATE DATABASE.atexithandler drops them all withDROP DATABASE ... WITH (FORCE)when the test process exits.Drop: most apps live in astaticshared by a test file, and statics are never dropped. Under nextest a process is one test; undercargo testit is one binary.Tests
tests/test_databases_are_dropped.rsruns a child test process that spawns an app, then checks that the database is gone. It failed against the old code (database ... outlived the test process) and passes now.cargo nextest run --tests -E 'not binary(bdd)'passed 2967 of 2967, with 0 new databases left (4450 before, 4450 after).cargo test --test bdd: 334 scenarios passed, 0 new databases left.clippyandrustfmtreport nothing in the changed files.Once this is merged, #310, #312 and the others need a re-run (or a merge of
dev) to go green.🤖 Generated with Claude Code