fix: ensure fresh test db's aren't accidentally deleted by do_cleanup #2454
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.
I recently encountered a panic in our CI where a test db created by the
#[sqlx::test]
macro was seemingly missing, right after it was created and right before we connected to it.Fortunately, it wasn't too hard to find the problem:
If the first test thread is a bit slow after it acquires the
DO_CLEANUP
permit, it can accidentally delete a fresh test db created by another thread right before that other thread has a chance to open its connection.I have a branch (phlip9@60a5955) with some
thread::sleep
's sprinkled around that manages to reproduce this panic almost 100% of the time. Run the failing test with./x.py -e postgres_15_tokio --test postgres-test-db-race
or./x.py -e mysql_8_tokio --test mysql-test-db-race
.The fix in this PR simply records the current timestamp before we acquire the
DO_CLEANUP
permit and only cleans up test db's created before then.Note: the next commit in that branch contains the fix, so we can see that the issue is resolved:
phlip9@1d78ba2