mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-06 07:48:06 +00:00
test: make three flaky unit tests deterministic (#50114)
* test: make four flaky unit tests deterministic The skill archive fixtures stamped the current time into zip bytes used as parametrize ids, so xdist workers collected different ids and errored the whole shard. They now use a fixed timestamp. The usage-based v2 override test pinned no clock, so a minute boundary between rpm checks reset the counter. It now pins get_utc_datetime the way #49505 does. The stalled-burst DB lookup test asserted a 2s wall-clock bound. It now asserts every lookup was waiting at once, which fails if lookups are serialized. The long tool_search placement test asserted a 1s wall-clock bound. It keeps the placement assertion and drops the bound, as #49505 did for the json accumulator * test(skills): drop the archive fixture timestamp change now that #50118 removed its test
This commit is contained in:
parent
4e769d153a
commit
8fcb016dc6
3 changed files with 25 additions and 8 deletions
|
|
@ -327,7 +327,7 @@ EMPTY_ASSISTANT = pytest.mark.parametrize(
|
|||
)
|
||||
|
||||
|
||||
def test_flagged_placement_handles_a_long_run_of_unanswered_tool_search_uses_in_linear_time():
|
||||
def test_flagged_placement_turns_reminders_before_a_long_run_of_unanswered_tool_search_uses_into_user_turns():
|
||||
search_uses: Final = tuple(
|
||||
{
|
||||
"role": "assistant",
|
||||
|
|
@ -349,12 +349,9 @@ def test_flagged_placement_handles_a_long_run_of_unanswered_tool_search_uses_in_
|
|||
{"role": "user", "content": "end"},
|
||||
]
|
||||
|
||||
started: Final = time.perf_counter()
|
||||
placed: Final = place_mid_conversation_system(messages, supports_mid_conversation_system=True)
|
||||
elapsed: Final = time.perf_counter() - started
|
||||
|
||||
assert set(_roles(placed)[:21]) == {"user"}
|
||||
assert elapsed < 1.0
|
||||
|
||||
|
||||
def test_flagged_placement_merges_every_system_run_that_shares_a_user_turn():
|
||||
|
|
|
|||
|
|
@ -46,21 +46,37 @@ async def test_bounded_db_lookup_returns_a_prompt_answer_without_recording_a_sta
|
|||
assert tracker.stalled_within(30) is False
|
||||
|
||||
|
||||
class _PendingLookups:
|
||||
def __init__(self) -> None:
|
||||
self.pending = 0
|
||||
self.peak = 0
|
||||
|
||||
async def never_answers(self) -> None:
|
||||
self.pending += 1
|
||||
self.peak = max(self.peak, self.pending)
|
||||
try:
|
||||
await asyncio.Event().wait()
|
||||
finally:
|
||||
self.pending -= 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bounded_db_lookup_fails_a_whole_stalled_burst_within_one_deadline():
|
||||
tracker: Final = DBLookupStallTracker()
|
||||
burst: Final = 200
|
||||
started: Final = time.monotonic()
|
||||
lookups: Final = _PendingLookups()
|
||||
|
||||
results: Final = await asyncio.gather(
|
||||
*(
|
||||
bounded_db_lookup(_never_answers(), name=f"key-{i}", deadline_seconds=0.1, tracker=tracker)
|
||||
bounded_db_lookup(lookups.never_answers(), name=f"key-{i}", deadline_seconds=0.1, tracker=tracker)
|
||||
for i in range(burst)
|
||||
),
|
||||
return_exceptions=True,
|
||||
)
|
||||
|
||||
assert time.monotonic() - started < 2
|
||||
assert lookups.peak == burst, (
|
||||
f"only {lookups.peak} of {burst} stalled lookups were waiting on their deadline together"
|
||||
)
|
||||
assert len(results) == burst
|
||||
assert all(isinstance(result, DBLookupDeadlineExceeded) for result in results)
|
||||
assert tracker.stalled_within(30) is True
|
||||
|
|
|
|||
|
|
@ -1022,7 +1022,11 @@ async def test_usage_based_v2_override_stays_scoped_to_the_request_that_asked_fo
|
|||
await _mock_completion(router, routing_strategy="usage-based-routing-v2")
|
||||
|
||||
|
||||
def test_sync_usage_based_v2_override_stays_scoped_to_the_request_that_asked_for_it():
|
||||
def test_sync_usage_based_v2_override_stays_scoped_to_the_request_that_asked_for_it(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
"litellm.router_strategy.lowest_tpm_rpm_v2.get_utc_datetime",
|
||||
lambda: datetime.datetime(2026, 1, 1, 12, 0, 30, tzinfo=datetime.timezone.utc),
|
||||
)
|
||||
router = Router(model_list=_rpm_limited_model_list(), routing_strategy="simple-shuffle", num_retries=0)
|
||||
messages = [{"role": "user", "content": "hi"}]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue