summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2025-10-21 19:09:32 -0400
committerNatalia <124304+nessita@users.noreply.github.com>2025-10-29 09:12:12 -0300
commit69386758efaae997bc3fc5b8de0e742033fec662 (patch)
tree79dccdc60366452bcfb263123b2ed24ec70834f7 /django
parentf13e6c90cfc1a35888df801c36bf0e5c080515a9 (diff)
[6.0.x] Fixed #36678 -- Limited retries in ParallelTestRunner.
Thanks Natalia Bidart for the review. Backport of 1aa69a7491ce7f7f1f164a26a3dfaaa1aeeab217 from main.
Diffstat (limited to 'django')
-rw-r--r--django/test/runner.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/django/test/runner.py b/django/test/runner.py
index 41c9dbd10c..fe90665d7f 100644
--- a/django/test/runner.py
+++ b/django/test/runner.py
@@ -1,6 +1,7 @@
import argparse
import ctypes
import faulthandler
+import functools
import hashlib
import io
import itertools
@@ -480,6 +481,16 @@ def _init_worker(
)
+def _safe_init_worker(init_worker, counter, *args, **kwargs):
+ try:
+ init_worker(counter, *args, **kwargs)
+ except Exception:
+ with counter.get_lock():
+ # Set a value that will not increment above zero any time soon.
+ counter.value = -1000
+ raise
+
+
def _run_subsuite(args):
"""
Run a suite of tests with a RemoteTestRunner and return a RemoteTestResult.
@@ -553,7 +564,7 @@ class ParallelTestSuite(unittest.TestSuite):
counter = multiprocessing.Value(ctypes.c_int, 0)
pool = multiprocessing.Pool(
processes=self.processes,
- initializer=self.init_worker.__func__,
+ initializer=functools.partial(_safe_init_worker, self.init_worker.__func__),
initargs=[
counter,
self.initial_settings,
@@ -580,7 +591,11 @@ class ParallelTestSuite(unittest.TestSuite):
try:
subsuite_index, events = test_results.next(timeout=0.1)
- except multiprocessing.TimeoutError:
+ except multiprocessing.TimeoutError as err:
+ if counter.value < 0:
+ err.add_note("ERROR: _init_worker failed, see prior traceback")
+ pool.close()
+ raise
continue
except StopIteration:
pool.close()