Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(grouping): Fix and refactor
save_aggregate
test (#78528)
In an upcoming PR, `_save_aggregate_new` is going to get absorbed into its caller, `assign_event_to_group`. While working on that PR, one of the things I did was to rename (and move) the `test_save_aggregate.py` test module (mostly because `save_aggregate_new` is going away, but also to better reflect what it's actually testing, which is the locking behavior around new group creation). It seemed a fairly benign change, but alas, suddenly a whole bunch of totally unrelated tests starting failing in CI (but only in CI - not locally). It turns out the problem was that the move/rename caused the `save_aggregate` tests to run in a different shard, which revealed the fact that the tests aren't actually thread-safe. (Indeed, they never have been, but until my change they hadn't been running alongside any tests which were sensitive to that.) More specifically, the problem is that the mocking done in the tests is done in each thread individually, rather than before the threads are split off. As far as I understand, this allows the mocking to interact with threads running other tests, thereby breaking them. The fix, therefore, was to move the mocking out to the main level of the test function. As a bonus, this allowed for some further simplification: Because mocking isn't thread-safe, the code run in the threads needed a `try-finally`, because sometimes the mocking just didn't happen, leading to errors. This also meant that we had to manually close the transaction, because said errors would prevent it from closing automatically. With the threading fix, we now don't need either of those things. So this PR makes those changes, and also pulls in a few refactors which had originally been in that PR. Mostly they're cosmetic - moving things around, clarifying some comments, etc. The only substantive change pulled from that PR was switching from testing whether or not things are working (`is_race_free`) to whether or not they aren't (`lock_disabled`).
- Loading branch information