test_stress.py
python
sha256:2313b6a6353294a0ca08ff579624198da250b99163a86215aed31a905912e360
Land Scooling Lab T0/T2 training contract and seven-tier tests
Human
minor
⚠ breaking
42 days ago
| 1 | """Stress tier tests for duplicate creation and fixture queue limits.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import concurrent.futures |
| 6 | import unittest |
| 7 | |
| 8 | from scooling_lab_helpers import valid_payload |
| 9 | |
| 10 | from scooling_lab.errors import ApiError, ErrorCode |
| 11 | from scooling_lab.service import TrainingApiService |
| 12 | from scooling_lab.store import TrainingJobStore |
| 13 | |
| 14 | |
| 15 | class ScoolingLabStressTests(unittest.TestCase): |
| 16 | """Stress tests for deterministic idempotency and bounded queues.""" |
| 17 | |
| 18 | def test_stress_concurrent_duplicate_create_is_deduplicated(self) -> None: |
| 19 | """Many concurrent duplicate creates return one deterministic job id.""" |
| 20 | |
| 21 | service = TrainingApiService(TrainingJobStore(), auto_run_worker=False) |
| 22 | payload = valid_payload("duplicate") |
| 23 | |
| 24 | with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: |
| 25 | results = list( |
| 26 | executor.map(lambda _: service.create_training_job(payload), range(24)) |
| 27 | ) |
| 28 | |
| 29 | job_ids = {result["id"] for result in results} |
| 30 | self.assertEqual(len(job_ids), 1) |
| 31 | self.assertEqual(results[0]["status"], "queued") |
| 32 | |
| 33 | def test_stress_many_fixture_jobs_respect_queue_limit(self) -> None: |
| 34 | """The fixture queue rejects excess queued/running jobs deterministically.""" |
| 35 | |
| 36 | service = TrainingApiService( |
| 37 | TrainingJobStore(queue_limit=2), auto_run_worker=False |
| 38 | ) |
| 39 | service.create_training_job(valid_payload("queue-a")) |
| 40 | service.create_training_job(valid_payload("queue-b")) |
| 41 | |
| 42 | with self.assertRaises(ApiError) as raised: |
| 43 | service.create_training_job(valid_payload("queue-c")) |
| 44 | self.assertEqual(raised.exception.code, ErrorCode.QUEUE_LIMIT_EXCEEDED) |
| 45 | |
| 46 | |
| 47 | if __name__ == "__main__": |
| 48 | unittest.main() |
File History
1 commit
sha256:2313b6a6353294a0ca08ff579624198da250b99163a86215aed31a905912e360
Land Scooling Lab T0/T2 training contract and seven-tier tests
Human
minor
⚠
42 days ago