Skip to content

Commit 7e3c248

Browse files
committed
Add analyze-CI-shard-timeout.py script.
This can be used to analyze a CI shard log from a timed out job to see which tests never finished.
1 parent 93f6430 commit 7e3c248

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

scripts/analyze-CI-shard-timeout.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import re
5+
import sys
6+
from pathlib import Path
7+
from textwrap import dedent
8+
from typing import Any
9+
10+
11+
def analyze(log: Path) -> Any:
12+
tests: dict[str, bool] = {}
13+
with log.open() as fp:
14+
for line in fp:
15+
# E.G.: 2024-11-13T06:29:33.3456360Z tests/integration/test_issue_1018.py::test_execute_module_alter_sys[ep-function-zipapp-VENV]
16+
match = re.match(r"^.*\d+Z (?P<test>tests/\S+(?:\[[^\]]+\])?).*", line)
17+
if match:
18+
test = match.group("test")
19+
if test not in tests:
20+
tests[test] = False
21+
continue
22+
23+
# E.G.: 2024-11-13T06:29:33.3478200Z [gw3] PASSED tests/integration/venv_ITs/test_issue_1745.py::test_interpreter_mode_python_options[-c <code>-VENV]
24+
match = re.match(r"^.*\d+Z \[gw\d+\] [A-Z]+ (?P<test>tests/\S+(?:\[[^\]]+\])?).*", line)
25+
if match:
26+
tests[match.group("test")] = True
27+
continue
28+
29+
hung_tests = sorted(test for test, complete in tests.items() if not complete)
30+
if hung_tests:
31+
return f"The following tests never finished:\n{os.linesep.join(hung_tests)}"
32+
33+
34+
def main() -> Any:
35+
if len(sys.argv) != 2:
36+
return dedent(
37+
f"""\
38+
Usage: {sys.argv[0]} <CI log file>
39+
40+
Analyzes a Pex CI log file from a timed-out shard to determine
41+
which tests never completed.
42+
"""
43+
)
44+
45+
log = Path(sys.argv[1])
46+
if not log.exists():
47+
return f"The log specified at {sys.argv[0]} does not exist."
48+
49+
return analyze(Path(sys.argv[1]))
50+
51+
52+
if __name__ == "__main__":
53+
sys.exit(main())

0 commit comments

Comments
 (0)