Skip to content

Commit 520d67f

Browse files
authored
tests/integration: print times for each step and flush to see it in CI (#1547)
@fw-immunant, this should hopefully fix why it wasn't printing each step until everything was finished. I also added times for each step (in addition to the total times for each project that we print at the end).
2 parents b648f56 + 3c70543 commit 520d67f

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

tests/integration/tests/__init__.py

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ def print_log_tail_on_fail(script_path):
6363
assert tail.stdout is not None
6464
for line in tail.stdout:
6565
print(line.decode().rstrip())
66+
sys.stdout.flush()
6667
else:
6768
print(
6869
"{color}Missing log file: {logf}{nocolor}".format(
6970
color=Colors.WARNING, logf=logfile, nocolor=Colors.NO_COLOR
70-
)
71+
),
72+
flush=True,
7173
)
7274

7375
script_path = os.path.join(self.dir, script)
@@ -76,15 +78,17 @@ def print_log_tail_on_fail(script_path):
7678
print(
7779
"{color}Missing script: {script}{nocolor}".format(
7880
color=Colors.FAIL, script=script_path, nocolor=Colors.NO_COLOR
79-
)
81+
),
82+
flush=True,
8083
)
8184
return False
8285

8386
if not os.access(script_path, os.X_OK):
8487
print(
8588
"{color}Script is not executable: {script}{nocolor}".format(
8689
color=Colors.FAIL, script=script_path, nocolor=Colors.NO_COLOR
87-
)
90+
),
91+
flush=True,
8892
)
8993
return False
9094

@@ -97,8 +101,19 @@ def print_log_tail_on_fail(script_path):
97101
stage=stage,
98102
script=relpath,
99103
)
104+
fill = (75 - len(line)) * "."
100105
else:
101106
line = ""
107+
fill = ""
108+
start_time = perf_counter()
109+
110+
def print_outcome(outcome: str, color: str):
111+
end_time = perf_counter()
112+
elapsed_time = timedelta(seconds=end_time - start_time)
113+
print(
114+
f"{line}{fill} ({elapsed_time}) {color}{outcome}{Colors.NO_COLOR}",
115+
flush=True,
116+
)
102117

103118
# if we already have `compile_commands.json`, skip the build stages
104119
if stage in ["autogen", "configure", "make"]:
@@ -108,10 +123,7 @@ def print_log_tail_on_fail(script_path):
108123

109124
if use_cached_cc_cmds:
110125
if not verbose:
111-
fill = (75 - len(line)) * "."
112-
color = Colors.OKBLUE
113-
msg = "OK_CACHED"
114-
print(f"{line}{fill} {color}{msg}{Colors.NO_COLOR}")
126+
print_outcome(outcome="OK_CACHED", color=Colors.OKBLUE)
115127
return True
116128
elif emsg:
117129
if verbose:
@@ -124,30 +136,33 @@ def print_log_tail_on_fail(script_path):
124136
# noinspection PyBroadException
125137
try:
126138
if verbose:
127-
subprocess.check_call(cwd=self.dir, args=[script_path])
139+
stdout = None
140+
stderr = None
128141
else:
129-
subprocess.check_call(
130-
cwd=self.dir,
131-
args=[script_path],
132-
stdout=subprocess.DEVNULL,
133-
stderr=subprocess.DEVNULL,
142+
stdout = subprocess.DEVNULL
143+
stderr = subprocess.DEVNULL
144+
subprocess.check_call(
145+
cwd=self.dir,
146+
args=[script_path],
147+
stdout=stdout,
148+
stderr=stderr,
149+
)
150+
if not verbose:
151+
print_outcome(
152+
outcome="OK_XFAIL" if xfail else "OK",
153+
color=Colors.WARNING if xfail else Colors.OKGREEN,
134154
)
135-
136-
fill = (75 - len(line)) * "."
137-
color = Colors.WARNING if xfail else Colors.OKGREEN
138-
msg = "OK_XFAIL" if xfail else "OK"
139-
print(f"{line}{fill} {color}{msg}{Colors.NO_COLOR}")
140155
return True
141156
except KeyboardInterrupt:
142157
if not verbose:
143-
print(f"{line}: {Colors.WARNING}INTERRUPT{Colors.NO_COLOR}")
158+
print_outcome(outcome="INTERRUPT", color=Colors.WARNING)
144159
exit(1)
145160
except Exception: # noqa
146161
if not verbose:
147-
outcome = "XFAIL" if xfail else "FAIL"
148-
fill = (75 - len(line)) * "."
149-
color = Colors.OKBLUE if xfail else Colors.FAIL
150-
print(f"{line}{fill} {color}{outcome}{Colors.NO_COLOR}")
162+
print_outcome(
163+
outcome="XFAIL" if xfail else "FAIL",
164+
color=Colors.OKBLUE if xfail else Colors.FAIL,
165+
)
151166
print_log_tail_on_fail(script_path)
152167
return False
153168

0 commit comments

Comments
 (0)