gh-109917: Fix test instability in test_concurrent_futures (#110306)

The test had an instability issue due to the ordering of the dummy
queue operation and the real wakeup pipe operations. Both primitives
are thread safe but not done atomically as a single update and may
interleave arbitrarily. With the old order of operations this can lead
to an incorrect state where the dummy queue is full but the wakeup
pipe is empty. By swapping the order in clear() I think this can no
longer happen in any possible operation interleaving (famous last
words).
This commit is contained in:
elfstrom 2023-10-03 23:59:49 +02:00 committed by GitHub
parent 4467d2c3ac
commit a376a72bd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -286,11 +286,12 @@ class ExecutorDeadlockTest:
super().wakeup()
def clear(self):
super().clear()
try:
while True:
self._dummy_queue.get_nowait()
except queue.Empty:
super().clear()
pass
with (unittest.mock.patch.object(futures.process._ExecutorManagerThread,
'run', mock_run),