Skip to content

Commit a4609d2

Browse files
committed
Log worker ID when running tests
1 parent 6547fa5 commit a4609d2

File tree

1 file changed

+15
-14
lines changed
  • graalpython/com.oracle.graal.python.test/src

1 file changed

+15
-14
lines changed

graalpython/com.oracle.graal.python.test/src/runner.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -335,16 +335,16 @@ def __init__(self, *, failfast: bool, report_durations: int | None):
335335
self.total_duration = 0.0
336336

337337
@staticmethod
338-
def report_start(test_id: TestId):
339-
log(f"{test_id} ... ", incomplete=True)
338+
def report_start(test_id: TestId, prefix=''):
339+
log(f"{prefix}{test_id} ... ", incomplete=True)
340340

341-
def report_result(self, result: TestResult):
341+
def report_result(self, result: TestResult, prefix=''):
342342
self.results.append(result)
343343
message = f"{result.test_id} ... {result.status}"
344344
if result.status == TestStatus.SKIPPED and result.param:
345-
message = f"{message} {result.param!r}"
345+
message = f"{prefix}{message} {result.param!r}"
346346
else:
347-
message = f"{message} ({result.duration:.2f}s)"
347+
message = f"{prefix}{message} ({result.duration:.2f}s)"
348348
log(message)
349349

350350
def tests_failed(self):
@@ -532,10 +532,10 @@ def __init__(self, *, num_processes, subprocess_args, separate_workers, timeout_
532532
self.crashes = []
533533
self.default_test_timeout = 600
534534

535-
def report_result(self, result: TestResult):
535+
def report_result(self, result: TestResult, prefix=''):
536536
if self.failfast and result.status in FAILED_STATES:
537537
self.stop_event.set()
538-
super().report_result(result)
538+
super().report_result(result, prefix=prefix)
539539

540540
def tests_failed(self):
541541
return super().tests_failed() or bool(self.crashes)
@@ -608,7 +608,7 @@ def run_tests(self, tests: list['TestSuite']):
608608
log(crash)
609609

610610
def run_partitions_in_subprocesses(self, executor, partitions: list[list['Test']]):
611-
workers = [SubprocessWorker(self, partition) for i, partition in enumerate(partitions)]
611+
workers = [SubprocessWorker(i, self, partition) for i, partition in enumerate(partitions)]
612612
futures = [executor.submit(worker.run_in_subprocess_and_watch) for worker in workers]
613613

614614
def dump_worker_status():
@@ -652,7 +652,8 @@ def sigterm_handler(_signum, _frame):
652652

653653

654654
class SubprocessWorker:
655-
def __init__(self, runner: ParallelTestRunner, tests: list['Test']):
655+
def __init__(self, worker_id: int, runner: ParallelTestRunner, tests: list['Test']):
656+
self.prefix = f'[worker-{worker_id + 1}] '
656657
self.runner = runner
657658
self.stop_event = runner.stop_event
658659
self.lock = threading.RLock()
@@ -675,7 +676,7 @@ def process_event(self, event):
675676
except ValueError:
676677
# It executed something we didn't ask for. Not sure why this happens
677678
log(f'WARNING: unexpected test started {test_id}')
678-
self.runner.report_start(test_id)
679+
self.runner.report_start(test_id, prefix=self.prefix)
679680
with self.lock:
680681
self.last_started_test_id = test_id
681682
self.last_started_time = time.time()
@@ -694,7 +695,7 @@ def process_event(self, event):
694695
output=test_output,
695696
duration=event.get('duration'),
696697
)
697-
self.runner.report_result(result)
698+
self.runner.report_result(result, prefix=self.prefix)
698699
with self.lock:
699700
self.last_started_test_id = None
700701
self.last_started_time = time.time() # Starts timeout for the following teardown/setup
@@ -846,7 +847,7 @@ def run_in_subprocess_and_watch(self):
846847
param=message,
847848
output=output,
848849
duration=(time.time() - self.last_started_time),
849-
))
850+
), prefix=self.prefix)
850851
if blame_id is not self.last_started_test_id:
851852
# If we're here, it means we didn't know exactly which test we were executing, we were
852853
# somewhere in between
@@ -1332,15 +1333,15 @@ def main_extract_test_timings(args):
13321333

13331334
# Download the log file
13341335
with urllib.request.urlopen(args.url) as response:
1335-
log = response.read().decode("utf-8", errors="replace")
1336+
log_content = response.read().decode("utf-8", errors="replace")
13361337

13371338
pattern = re.compile(
13381339
r"^(?P<path>[^\s:]+)::\S+ +\.\.\. (?:ok|FAIL|ERROR|SKIPPED|expected failure|unexpected success|\S+) \((?P<time>[\d.]+)s\)",
13391340
re.MULTILINE,
13401341
)
13411342

13421343
timings = {}
1343-
for match in pattern.finditer(log):
1344+
for match in pattern.finditer(log_content):
13441345
raw_path = match.group("path").replace("\\", "/")
13451346
t = float(match.group("time"))
13461347
timings.setdefault(raw_path, 0.0)

0 commit comments

Comments
 (0)