mirror of
https://github.com/basnijholt/compose-farm.git
synced 2026-02-03 14:13:26 +00:00
Return early from CLI startup test when under threshold
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user