Return early from CLI startup test when under threshold

This commit is contained in:
Bas Nijholt
2025-12-17 08:56:35 -08:00
parent 129970379c
commit cdbe74ed89

View File

@@ -19,7 +19,7 @@ def test_cli_startup_time() -> None:
cf_path = shutil.which("cf")
assert cf_path is not None, "cf command not found in PATH"
# Run multiple times and take the minimum to reduce noise
# Run up to 3 times, return early if we hit the threshold
times: list[float] = []
for _ in range(3):
start = time.perf_counter()
@@ -35,16 +35,18 @@ def test_cli_startup_time() -> None:
# Verify the command succeeded
assert result.returncode == 0, f"CLI failed: {result.stderr}"
best_time = min(times)
avg_time = sum(times) / len(times)
# Pass early if under threshold
if elapsed < CLI_STARTUP_THRESHOLD:
print(f"\nCLI startup: {elapsed:.3f}s (threshold: {CLI_STARTUP_THRESHOLD}s)")
return
# Always print timing info - visible in CI logs even on failure
# All attempts exceeded threshold
best_time = min(times)
msg = (
f"\nCLI startup times: {[f'{t:.3f}s' for t in times]}\n"
f"Best: {best_time:.3f}s, Avg: {avg_time:.3f}s, Threshold: {CLI_STARTUP_THRESHOLD}s"
f"Best: {best_time:.3f}s, Threshold: {CLI_STARTUP_THRESHOLD}s"
)
print(msg)
assert best_time < CLI_STARTUP_THRESHOLD, (
f"CLI startup too slow!\n{msg}\nCheck for slow imports."
)
err_msg = f"CLI startup too slow!\n{msg}\nCheck for slow imports."
raise AssertionError(err_msg)