Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions tests/e2e/batches/batch_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ def retrieve_batch(self, batch_id: str, *, key: str, provider: str | None = None
def cancel_batch(self, batch_id: str, *, key: str, provider: str | None = None) -> Result[BatchObject]: ...


class BatchCleanupLeftover(UserWarning):
pass


def cleanup_result[R: BaseModel](
action: Callable[[], Result[R]], *, wait: Callable[[float], None] = sleep
) -> Result[R]:
Expand Down Expand Up @@ -68,7 +64,7 @@ def cleanup_file(client: BatchCleanupClient, file_id: str, *, key: str, provider
if isinstance(result, UnknownApiError) and result.status_code == 400 and FILE_IN_USE_REFUSAL in result.body:
warnings.warn(
f"Left file {file_id} in place: LiteLLM refused to delete it while a batch still references it",
BatchCleanupLeftover,
UserWarning,
stacklevel=2,
)
return
Expand Down Expand Up @@ -140,7 +136,7 @@ def cleanup_batch(
)
warnings.warn(
f"Left batch {batch_id} cancelling after {BATCH_CANCEL_TIMEOUT_SECONDS}s for the provider to finish",
BatchCleanupLeftover,
UserWarning,
stacklevel=2,
)
return
Expand Down
5 changes: 2 additions & 3 deletions tests/e2e/batches/test_batch_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from batch_cleanup import (
BATCH_CANCEL_TIMEOUT_SECONDS,
CLEANUP_DELAYS,
BatchCleanupLeftover,
cleanup_batch,
cleanup_file,
cleanup_result,
Expand Down Expand Up @@ -141,7 +140,7 @@ def test_delete_refused_because_a_batch_still_references_the_file_is_left_and_re
calls=ExpectedCalls((f"delete None {MANAGED_FILE_ID}",)),
files=(UnknownApiError(status_code=400, body=IN_USE_REFUSAL),),
)
with pytest.warns(BatchCleanupLeftover, match=MANAGED_FILE_ID):
with pytest.warns(UserWarning, match=MANAGED_FILE_ID):
cleanup_file(client, MANAGED_FILE_ID, key="test-key")
client.calls.assert_done()

Expand Down Expand Up @@ -241,7 +240,7 @@ def test_batch_still_cancelling_at_the_deadline_and_its_input_file_are_left_and_
key: Final = manager.key()
manager.defer(lambda: cleanup_file(client, MANAGED_FILE_ID, key=key))
manager.defer(lambda: cleanup_batch(client, MANAGED_BATCH_ID, key=key, clock=ticks))
with pytest.warns(BatchCleanupLeftover) as leftovers:
with pytest.warns(UserWarning, match="^Left ") as leftovers:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Uncaught warning path remains untested Both updated tests catch cleanup warnings in-process. Neither checks that an uncaught warning reaches the pytest controller under xdist, so the reported CI crash could return while these tests stay green. A focused xdist regression test would cover that path

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

manager.teardown()
client.calls.assert_done()
messages: Final = tuple(str(warning.message) for warning in leftovers)
Expand Down
7 changes: 6 additions & 1 deletion tests/integration/_support/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,18 @@ def request(
*,
key: str | None = None,
params: Mapping[str, str] | None = None,
headers: Mapping[str, str] | None = None,
) -> httpx.Response:
request_headers: Final = {
"Authorization": f"Bearer {self.key if key is None else key}",
**(headers or {}),
}
return self.client.request(
method,
path,
json=body,
params=params,
headers={"Authorization": f"Bearer {self.key if key is None else key}"},
headers=request_headers,
)

def post(self, path: str, body: Mapping[str, JsonValue], *, key: str | None = None) -> dict[str, JsonValue]:
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/_support/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ def owned_proxy(
*,
config: Path | None = None,
remove_environment: tuple[str, ...] = (),
workers: int = 1,
) -> Iterator[Gateway]:
with owned_proxy_process(
gateway, directory, overrides, config=config, remove_environment=remove_environment
gateway, directory, overrides, config=config, remove_environment=remove_environment, workers=workers
) as owned:
yield owned.gateway

Expand All @@ -76,6 +77,7 @@ def owned_proxy_process(
*,
config: Path | None = None,
remove_environment: tuple[str, ...] = (),
workers: int = 1,
) -> Iterator[OwnedProxy]:
with socket.socket() as reserve:
reserve.bind(("127.0.0.1", 0))
Expand Down Expand Up @@ -104,7 +106,7 @@ def owned_proxy_process(
"--port",
str(port),
"--num_workers",
"1",
str(workers),
"--telemetry",
"False",
"--use_prisma_db_push",
Expand Down
Loading