Skip to content

Commit 9bc36df

Browse files
authored
[parallel_testsuite.py] Simplify allowed_failures_counter (#25767)
We do all the modification of allowed_failures_counter on the main thread without the need for a lock. I believe this was not possible prior #25751.
1 parent ad2bf6f commit 9bc36df

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

test/parallel_testsuite.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def cap_max_workers_in_pool(max_workers, is_browser):
4545

4646

4747
def run_test(args):
48-
test, allowed_failures_counter, lock, buffer = args
48+
test, allowed_failures_counter, buffer = args
4949
# If we have exceeded the number of allowed failures during the test run,
5050
# abort executing further tests immediately.
5151
if allowed_failures_counter and allowed_failures_counter.value < 0:
@@ -66,12 +66,6 @@ def run_test(args):
6666
test.set_temp_dir(temp_dir)
6767
try:
6868
test(result)
69-
70-
# Alert all other multiprocess pool runners that they need to stop executing further tests.
71-
if result.test_result not in ['success', 'skipped']:
72-
if allowed_failures_counter is not None:
73-
with lock:
74-
allowed_failures_counter.value -= 1
7569
finally:
7670
result.elapsed = time.perf_counter() - start_time
7771

@@ -174,20 +168,22 @@ def run(self, result):
174168
if python_multiprocessing_structures_are_buggy():
175169
# When multiprocessing shared structures are buggy we don't support failfast
176170
# or the progress bar.
177-
allowed_failures_counter = lock = None
171+
allowed_failures_counter = None
178172
if self.max_failures < 2**31 - 1:
179173
errlog('The version of python being used is not compatible with --failfast and --max-failures options. See https://github.com/python/cpython/issues/71936')
180174
sys.exit(1)
181175
else:
182176
allowed_failures_counter = manager.Value('i', self.max_failures)
183-
lock = manager.Lock()
184177

185178
results = []
186-
args = ((t, allowed_failures_counter, lock, result.buffer) for t in tests)
179+
args = ((t, allowed_failures_counter, result.buffer) for t in tests)
187180
for res in pool.imap_unordered(run_test, args, chunksize=1):
188181
# results may be be None if # of allowed errors was exceeded
189182
# and the harness aborted.
190183
if res:
184+
if res.test_result not in ['success', 'skipped'] and allowed_failures_counter is not None:
185+
# Signal existing multiprocess pool runners so that they can exit early if needed.
186+
allowed_failures_counter.value -= 1
191187
self.printOneResult(res)
192188
results.append(res)
193189

0 commit comments

Comments
 (0)