mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-04 07:27:51 +00:00
test: wait on events instead of fixed sleeps in the bridged failure and fallback tests
This commit is contained in:
parent
a874b8a1e6
commit
88075bd45a
2 changed files with 5 additions and 4 deletions
|
|
@ -793,16 +793,17 @@ class TestUpstreamFailureReachesTheProxyFailureHook:
|
|||
|
||||
def test_a_client_disconnect_during_the_failure_hook_lets_the_hook_finish(self):
|
||||
hook_started = anyio.Event()
|
||||
hook_released = anyio.Event()
|
||||
finished: list[Exception] = []
|
||||
|
||||
async def _slow_hook(failure: Exception) -> None:
|
||||
async def _held_hook(failure: Exception) -> None:
|
||||
hook_started.set()
|
||||
await anyio.sleep(0.05)
|
||||
await hook_released.wait()
|
||||
finished.append(failure)
|
||||
|
||||
async def _disconnect_mid_hook() -> None:
|
||||
wrapper = AnthropicResponsesStreamWrapper(
|
||||
responses_stream=_failing_after_one_delta(), model="m", litellm_logging_obj=_logging_obj_with_failure_hook(_slow_hook)
|
||||
responses_stream=_failing_after_one_delta(), model="m", litellm_logging_obj=_logging_obj_with_failure_hook(_held_hook)
|
||||
)
|
||||
|
||||
async def _consume() -> None:
|
||||
|
|
@ -813,6 +814,7 @@ class TestUpstreamFailureReachesTheProxyFailureHook:
|
|||
task_group.start_soon(_consume)
|
||||
await hook_started.wait()
|
||||
task_group.cancel_scope.cancel()
|
||||
hook_released.set()
|
||||
|
||||
asyncio.run(_disconnect_mid_hook())
|
||||
assert len(finished) == 1
|
||||
|
|
|
|||
|
|
@ -3745,7 +3745,6 @@ async def test_responses_fallback_sharing_the_proxy_logging_object_logs_the_fall
|
|||
)
|
||||
_ = [event async for event in response]
|
||||
await asyncio.wait_for(recorder.succeeded.wait(), timeout=10)
|
||||
await asyncio.sleep(0.5)
|
||||
|
||||
success: Final = recorder.successes[-1]
|
||||
assert (success["prompt_tokens"], success["completion_tokens"]) == (1000, 700)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue