test_performance.py
python
sha256:91e875d4a97bb1e35f37992f803988d5713931f1782d870c371c50054574af22
Add fixture provenance retention deletion
Human
minor
⚠ breaking
42 days ago
| 1 | """Performance tier tests for Scooling Lab bounded local operations.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from datetime import UTC, datetime, timedelta |
| 6 | import time |
| 7 | import unittest |
| 8 | |
| 9 | from scooling_lab_helpers import PROJECT_ROOT, valid_payload |
| 10 | |
| 11 | from scooling_lab.bom import main as bom_main |
| 12 | from scooling_lab.service import TrainingApiService |
| 13 | from scooling_lab.store import TrainingJobStore |
| 14 | |
| 15 | |
| 16 | class ScoolingLabPerformanceTests(unittest.TestCase): |
| 17 | """Performance tests for status/list endpoints and BOM scan budget.""" |
| 18 | |
| 19 | def test_performance_status_and_list_artifacts_are_bounded(self) -> None: |
| 20 | """Repeated status and artifact reads remain inside a local budget.""" |
| 21 | |
| 22 | service = TrainingApiService(TrainingJobStore()) |
| 23 | created = service.create_training_job(valid_payload("performance")) |
| 24 | job_id = str(created["id"]) |
| 25 | |
| 26 | start = time.perf_counter() |
| 27 | for _ in range(200): |
| 28 | self.assertEqual(service.get_training_job(job_id)["status"], "succeeded") |
| 29 | self.assertEqual(len(service.list_artifacts(job_id)["artifacts"]), 1) |
| 30 | elapsed = time.perf_counter() - start |
| 31 | |
| 32 | self.assertLess(elapsed, 1.0) |
| 33 | |
| 34 | def test_performance_bom_scan_runs_inside_ci_budget(self) -> None: |
| 35 | """The real BOM check completes within the configured CI budget.""" |
| 36 | |
| 37 | start = time.perf_counter() |
| 38 | exit_code = bom_main( |
| 39 | [ |
| 40 | "--root", |
| 41 | str(PROJECT_ROOT), |
| 42 | "--output", |
| 43 | "DEPENDENCIES.md", |
| 44 | "--check", |
| 45 | "--budget-seconds", |
| 46 | "30", |
| 47 | ] |
| 48 | ) |
| 49 | elapsed = time.perf_counter() - start |
| 50 | |
| 51 | self.assertEqual(exit_code, 0) |
| 52 | self.assertLess(elapsed, 30) |
| 53 | |
| 54 | def test_performance_provenance_emission_is_constant_time_bounded(self) -> None: |
| 55 | """Repeated provenance emission remains inside a fixed local budget.""" |
| 56 | |
| 57 | service = TrainingApiService(TrainingJobStore(queue_limit=1_200)) |
| 58 | |
| 59 | start = time.perf_counter() |
| 60 | for index in range(1_000): |
| 61 | created = service.create_training_job(valid_payload(f"provenance-{index}")) |
| 62 | provenance = service.get_provenance(str(created["id"])) |
| 63 | self.assertTrue(str(provenance["artifactHash"])) |
| 64 | elapsed = time.perf_counter() - start |
| 65 | |
| 66 | self.assertLess(elapsed, 3.0) |
| 67 | |
| 68 | def test_performance_sweep_is_bounded_over_ten_thousand_fixture_jobs(self) -> None: |
| 69 | """Retention sweep over N=10k fixture jobs completes inside CI budget.""" |
| 70 | |
| 71 | service = TrainingApiService(TrainingJobStore(queue_limit=10_500)) |
| 72 | payload_policy = {"policyClass": "ephemeral", "ttlSeconds": 60} |
| 73 | for index in range(10_000): |
| 74 | service.create_training_job(valid_payload(f"sweep-{index}", payload_policy)) |
| 75 | |
| 76 | start = time.perf_counter() |
| 77 | summary = service.sweep_expired_artifacts( |
| 78 | datetime.now(UTC) + timedelta(seconds=120) |
| 79 | ) |
| 80 | elapsed = time.perf_counter() - start |
| 81 | |
| 82 | self.assertEqual(summary["deletedCount"], 10_000) |
| 83 | self.assertLess(elapsed, 5.0) |
| 84 | |
| 85 | |
| 86 | if __name__ == "__main__": |
| 87 | unittest.main() |
File History
1 commit
sha256:91e875d4a97bb1e35f37992f803988d5713931f1782d870c371c50054574af22
Add fixture provenance retention deletion
Human
minor
⚠
42 days ago