Merge bitcoin/bitcoin#29497: test: simplify test_runner.py

0831b54dfca1b9e728295fff500215da14589fc0 test: simplify test_runner.py (tdb3)

Pull request description:

  Implements the simplifications to test_runner.py proposed by sipa in PR #23995.

  Remove the num_running variable as it can be implied by the length of the jobs list.

  Remove the i variable as it can be implied by the length of the test_results list.

  Instead of counting results to determine if finished, make the queue object itself
  responsible (by looking at running jobs and jobs left).

ACKs for top commit:
  mzumsande:
    re-ACK 0831b54
  davidgumberg:
    reACK 0831b54dfc
  marcofleon:
    re-ACK 0831b54dfca1b9e728295fff500215da14589fc0

Tree-SHA512: e5473e68d49cd779b29d97635329283ae7195412cb1e92461675715ca7eedb6519a1a93ba28d40ca6f015d270f7bcd3e77cef279d9cd655155ab7805b49638f1
This commit is contained in:
fanquake 2024-03-14 09:55:10 +00:00 committed by pasta
parent d0e15d59f8
commit 6d7aa3d978
No known key found for this signature in database
GPG Key ID: E2F3D7916E722D38

View File

@ -592,14 +592,12 @@ def run_tests(*, test_list, src_dir, build_dir, tmpdir, jobs=1, attempts=1, enab
max_len_name = len(max(test_list, key=len)) max_len_name = len(max(test_list, key=len))
test_count = len(test_list) test_count = len(test_list)
all_passed = True all_passed = True
i = 0 while not job_queue.done():
while i < test_count:
if failfast and not all_passed: if failfast and not all_passed:
break break
for test_result, testdir, stdout, stderr in job_queue.get_next(): for test_result, testdir, stdout, stderr in job_queue.get_next():
test_results.append(test_result) test_results.append(test_result)
i += 1 done_str = f"{len(test_results)}/{test_count} - {BOLD[1]}{test_result.name}{BOLD[0]}"
done_str = "{}/{} - {}{}{}".format(i, test_count, BOLD[1], test_result.name, BOLD[0])
if test_result.status == "Passed": if test_result.status == "Passed":
logging.debug("%s passed, Duration: %s s" % (done_str, test_result.time)) logging.debug("%s passed, Duration: %s s" % (done_str, test_result.time))
elif test_result.status == "Skipped": elif test_result.status == "Skipped":
@ -684,15 +682,16 @@ class TestHandler:
self.tmpdir = tmpdir self.tmpdir = tmpdir
self.test_list = test_list self.test_list = test_list
self.flags = flags self.flags = flags
self.num_running = 0
self.jobs = [] self.jobs = []
self.use_term_control = use_term_control self.use_term_control = use_term_control
self.attempts = attempts self.attempts = attempts
def done(self):
return not (self.jobs or self.test_list)
def get_next(self): def get_next(self):
while self.num_running < self.num_jobs and self.test_list: while len(self.jobs) < self.num_jobs and self.test_list:
# Add tests # Add tests
self.num_running += 1
test = self.test_list.pop(0) test = self.test_list.pop(0)
portseed = len(self.test_list) portseed = len(self.test_list)
portseed_arg = ["--portseed={}".format(portseed)] portseed_arg = ["--portseed={}".format(portseed)]
@ -764,7 +763,6 @@ class TestHandler:
continue continue
else: else:
status = "Failed" status = "Failed"
self.num_running -= 1
self.jobs.remove(job) self.jobs.remove(job)
if self.use_term_control: if self.use_term_control:
clearline = '\r' + (' ' * dot_count) + '\r' clearline = '\r' + (' ' * dot_count) + '\r'