Fix tests for cargo stress on free-threaded build #4469
Merged
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.
refs #4265
The free-threaded build has a lot of flaky tests at the moment and I'm trying various strategies to find them. Running
cargo test
in a bash while loop works well, butcargo stress
also seems to find interesting bugs. This fixes issues thatcargo stress
hits quickly on my local setup.The changes to
test_datetime_imports
can be hit in a regular gil-enabled python build, the test uses the filesystem assuming no other instances of the test function are running simultaneously. I updated it so it will create directories with unique names.The changes for the decref pool tests are because in the free-threaded build other threads are free to process the decref pool at any time, it's no longer locked by the GIL. That's fine, it doesn't matter if the owning thread or another random thread processes the pool. It does mean that the assertions in the tests are no longer always true and depend on timing. I added comments where I had to think really hard about scenarios where the assertions don't hold.
There's also one assertion that is changed because the
Py_DECREF
calls on the pending decref pool can happen concurrently with calls toPy_REFCNT
in other threads, making the result ofPy_REFCNT
racy. The mutex on the pending decrefs pool is implicitly released whenpending_decrefs
is dropped before calling the C API here:pyo3/src/gil.rs
Lines 276 to 281 in 2f5b45e