Skip to content

Commit 0844084

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#22249: test: kill process group to avoid dangling processes when using --failfast
451b96f test: kill process group to avoid dangling processes (S3RK) Pull request description: This is an alternative to #19281 This PR fixes a problem when after test failure with `--failfast` option there could be dangling nodes. The nodes will continue to occupy rpc/p2p ports on the machine and will cause further test failures. If there are any dangling nodes left at the end of the test run we kill the whole process group. Pros: the operations is immediate and won't lead to CI timeout Cons: the test_runner process is also killed and exit code is 137 Example output: ``` ... Early exiting after test failure TEST | STATUS | DURATION rpc_decodescript.py | ✓ Passed | 2 s rpc_deprecated.py | ✓ Passed | 2 s rpc_deriveaddresses.py | ✓ Passed | 2 s rpc_dumptxoutset.py | ✖ Failed | 2 s ALL | ✖ Failed | 8 s (accumulated) Runtime: 4 s Killed: 9 > echo $? 137 ``` ACKs for top commit: MarcoFalke: review ACK 451b96f aitorjs: ACK 451b96f. Manual testing with and without **--failfast**. Tree-SHA512: 87e510a1411b9e7571e63cf7ffc8b9a8935daf9112ffc0f069d6c406ba87743ec439808181f7e13cb97bb200fad528589786c47f0b43cf3a2ef0d06a23cb86dd
2 parents da69d99 + 451b96f commit 0844084

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

test/functional/test_runner.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import os
2020
import time
2121
import shutil
22+
import signal
2223
import subprocess
2324
import sys
2425
import tempfile
@@ -548,9 +549,11 @@ def run_tests(*, test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage=
548549

549550
all_passed = all(map(lambda test_result: test_result.was_successful, test_results)) and coverage_passed
550551

551-
# This will be a no-op unless failfast is True in which case there may be dangling
552-
# processes which need to be killed.
553-
job_queue.kill_and_join()
552+
# Clean up dangling processes if any. This may only happen with --failfast option.
553+
# Killing the process group will also terminate the current process but that is
554+
# not an issue
555+
if len(job_queue.jobs):
556+
os.killpg(os.getpgid(0), signal.SIGKILL)
554557

555558
sys.exit(not all_passed)
556559

@@ -647,16 +650,6 @@ def get_next(self):
647650
print('.', end='', flush=True)
648651
dot_count += 1
649652

650-
def kill_and_join(self):
651-
"""Send SIGKILL to all jobs and block until all have ended."""
652-
procs = [i[2] for i in self.jobs]
653-
654-
for proc in procs:
655-
proc.kill()
656-
657-
for proc in procs:
658-
proc.wait()
659-
660653

661654
class TestResult():
662655
def __init__(self, name, status, time):

0 commit comments

Comments
 (0)