Skip to content

Commit d0c196b

Browse files
fix: add validation tests and fix formatting for idle timeout
Github-Issue: #1283
1 parent f6a9145 commit d0c196b

File tree

2 files changed

+1148
-1244
lines changed

2 files changed

+1148
-1244
lines changed

tests/issues/test_1283_idle_session_cleanup.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,24 @@ async def test_multiple_sessions_reaped_independently():
159159
stop.set()
160160

161161

162+
def test_session_idle_timeout_rejects_negative():
163+
"""session_idle_timeout must be a positive number."""
164+
with pytest.raises(ValueError, match="positive number"):
165+
StreamableHTTPSessionManager(app=Server("test"), session_idle_timeout=-1)
166+
167+
168+
def test_session_idle_timeout_rejects_zero():
169+
"""session_idle_timeout must be a positive number."""
170+
with pytest.raises(ValueError, match="positive number"):
171+
StreamableHTTPSessionManager(app=Server("test"), session_idle_timeout=0)
172+
173+
174+
def test_session_idle_timeout_rejects_stateless():
175+
"""session_idle_timeout is not supported in stateless mode."""
176+
with pytest.raises(ValueError, match="not supported in stateless"):
177+
StreamableHTTPSessionManager(app=Server("test"), session_idle_timeout=30, stateless=True)
178+
179+
162180
@pytest.mark.anyio
163181
async def test_terminate_idempotency():
164182
"""Calling terminate() multiple times should be safe."""
@@ -303,8 +321,7 @@ async def instrumented_run(*args, **kwargs): # type: ignore[no-untyped-def]
303321
# should exit almost instantly after terminate(). We allow up to 2x
304322
# the idle timeout as a generous upper bound to avoid flakiness.
305323
assert total_elapsed < idle_timeout * 3, (
306-
f"run_server task took {total_elapsed:.3f}s to exit after pre_reap_time; "
307-
f"expected < {idle_timeout * 3:.1f}s"
324+
f"run_server task took {total_elapsed:.3f}s to exit after pre_reap_time; expected < {idle_timeout * 3:.1f}s"
308325
)
309326

310327
# The session must have been removed from tracking dicts.

0 commit comments

Comments
 (0)