[v1.x] Expire idle Streamable HTTP sessions by default and cap concurrent sessions (#3426)

This commit is contained in:
Max 2026-09-02 16:06:38 +01:00 • committed by GitHub
commit 92120b4b0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,27 @@
from collections.abc import Iterator
import pytest
from sse_starlette.sse import AppStatus
@pytest.fixture
def anyio_backend():
return "asyncio"
@pytest.fixture(autouse=True)
def reset_sse_starlette_exit_event() -> Iterator[None]:
"""sse-starlette<2 caches a module-level anyio.Event on AppStatus. Clear it
around each test so it is never bound to a closed event loop: any test that
serves an SSE response in process would otherwise inherit the event a
previous test created on another loop. Clearing it afterwards matters too,
because later test modules fork uvicorn subprocesses on Linux and would
otherwise inherit a stale event."""
def clear() -> None:
if hasattr(AppStatus, "should_exit_event"): # pragma: no cover
setattr(AppStatus, "should_exit_event", None)
clear()
yield
clear()