Skip to content

Commit 550de82

Browse files
author
Mateusz
committed
test: stabilize session detector perf and streaming 429 retry tests
Relax SessionDetector metadata timing ceiling under parallel CI (perf_counter, 100ms) instead of a 5ms wall-clock bound that flakes under xdist. Raise failure-handling total_timeout_budget in the streaming 429 keepalive retry test so elapsed budget work cannot expire before the second attempt when workers are contended. Made-with: Cursor
1 parent 3bf7231 commit 550de82

2 files changed

Lines changed: 30 additions & 27 deletions

File tree

tests/unit/connectors/test_openai_codex_session_detector.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -598,22 +598,23 @@ class TestSessionDetectorPerformance:
598598
reason="Measures actual detection performance to ensure it completes within acceptable time limits."
599599
)
600600
async def test_detection_completes_quickly(self):
601-
"""Test that detection completes within 5ms target."""
601+
"""Test that metadata detection stays fast (not pathological under CI load)."""
602602
detector = SessionDetector()
603603
metadata = {"agent": "kilocode"}
604604
request_data = MagicMock()
605605

606-
start_time = time.time()
606+
start_time = time.perf_counter()
607607
await detector.detect(
608608
request_data=request_data,
609609
metadata=metadata,
610610
session_id="test_session",
611611
backend="openai-codex",
612612
)
613-
elapsed_ms = (time.time() - start_time) * 1000
613+
elapsed_ms = (time.perf_counter() - start_time) * 1000
614614

615-
# Should complete well under 5ms
616-
assert elapsed_ms < 5.0
615+
# Under parallel pytest workers / Windows scheduling, sub-5ms wall time is
616+
# flaky; keep a tight but realistic ceiling for this trivial metadata path.
617+
assert elapsed_ms < 100.0, f"detection took {elapsed_ms:.1f}ms"
617618

618619
@pytest.mark.asyncio
619620
@real_time(

tests/unit/core/services/test_backend_service_streaming_rate_limit_retry.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ async def success_stream():
3333
content=success_stream(), media_type="text/event-stream", headers={}
3434
)
3535

36-
mock_backend.chat_completions = AsyncMock(
37-
side_effect=[
38-
BackendError(
39-
"Rate limited",
40-
status_code=429,
41-
details={"retry_after": 0.1},
42-
),
43-
success_response,
44-
]
45-
)
36+
mock_backend.chat_completions = AsyncMock(
37+
side_effect=[
38+
BackendError(
39+
"Rate limited",
40+
status_code=429,
41+
details={"retry_after": 0.1},
42+
),
43+
success_response,
44+
]
45+
)
4646

4747
backend_lifecycle_manager.get_or_create = AsyncMock(return_value=mock_backend)
4848

@@ -55,18 +55,20 @@ async def success_stream():
5555
session_service = MagicMock()
5656
session_service.get_session = AsyncMock(return_value=None)
5757

58-
config = AppConfig().model_copy(
59-
update={
60-
"failure_handling": FailureHandlingConfig(
61-
enabled=True,
62-
total_timeout_budget=0.5,
63-
max_silent_wait=60.0,
64-
keepalive_interval=1.0,
65-
max_failover_hops=5,
66-
min_retry_wait=0.1,
67-
)
68-
}
69-
)
58+
config = AppConfig().model_copy(
59+
update={
60+
"failure_handling": FailureHandlingConfig(
61+
enabled=True,
62+
# Budget must cover retry-after wait + keepalive scheduling under xdist;
63+
# 0.5s flakes when workers are busy before the second attempt runs.
64+
total_timeout_budget=15.0,
65+
max_silent_wait=60.0,
66+
keepalive_interval=1.0,
67+
max_failover_hops=5,
68+
min_retry_wait=0.1,
69+
)
70+
}
71+
)
7072

7173
# Mock other dependencies
7274
deps = {

0 commit comments

Comments
 (0)