ci: avoid races in tests asserting warnings #5357
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.
This PR avoids races in tests which use
warnings.capture_warnings
.While we had issues with
Py_GIL_DISABLED
with these tests previously,warnings.capture_warnings
, not being thread-safe of course means that no two rust tests doing such work can be run concurrently, because even GIL switches can lead to tests interleaving and therefore getting bad results.While we'd not observed these races on the GIL-enabled builds before, I think #5341 has actually gotten stuck due to this behavior because disallowing races to build types has introduced a new synchronization point between test threads.
I fix that problem in this PR by introducing a mutex into the
CatchWarnings
test helper; as long as all tests go through that helper they will be forced to run sequentially for the sensitive block. I had to rearrange the "test utils" file a bit so that it was available atcrate::test_utils
in all places it's used, so that the macros inside it work properly.As a result, I think I can enable all these tests on the free-threaded build too :)
cc @ngoldbaum