Server-side 2026-07-28 stateless support: classifier, driver split, server/discover (#2928)
This commit is contained in:
parent
44724284b3
commit
2397319a68
1 changed files with 2256 additions and 1088 deletions
|
|
@ -31,21 +31,20 @@ class _Lifespan:
|
|||
@pytest.mark.anyio
|
||||
async def test_context_exposes_lifespan_and_connection_and_forwards_base_context():
|
||||
captured: list[Context[_Lifespan]] = []
|
||||
conn = Connection.__new__(Connection) # placeholder until running_pair gives us the dispatcher
|
||||
conn_holder: list[Connection] = []
|
||||
|
||||
async def server_on_request(dctx: DCtx, method: str, params: Mapping[str, Any] | None) -> dict[str, Any]:
|
||||
ctx: Context[_Lifespan] = Context(dctx, lifespan=_Lifespan("app"), connection=conn)
|
||||
ctx: Context[_Lifespan] = Context(dctx, lifespan=_Lifespan("app"), connection=conn_holder[0])
|
||||
captured.append(ctx)
|
||||
return {}
|
||||
|
||||
async with running_pair(direct_pair, server_on_request=server_on_request) as (client, server, *_):
|
||||
# Now we have the server dispatcher; build the real Connection bound to it.
|
||||
conn.__init__(server, has_standalone_channel=True, session_id="sess-1")
|
||||
conn_holder.append(Connection.for_loop(server, session_id="sess-1"))
|
||||
with anyio.fail_after(5):
|
||||
await client.send_raw_request("t", None)
|
||||
ctx = captured[0]
|
||||
assert ctx.lifespan.name == "app"
|
||||
assert ctx.connection is conn
|
||||
assert ctx.connection is conn_holder[0]
|
||||
assert ctx.transport.kind == "direct"
|
||||
assert ctx.can_send_request is True
|
||||
assert ctx.session_id == "sess-1"
|
||||
|
|
@ -58,9 +57,7 @@ async def test_context_log_sends_request_scoped_message_notification():
|
|||
_, c_notify = echo_handlers(crec)
|
||||
|
||||
async def server_on_request(dctx: DCtx, method: str, params: Mapping[str, Any] | None) -> dict[str, Any]:
|
||||
ctx: Context[_Lifespan] = Context(
|
||||
dctx, lifespan=_Lifespan("app"), connection=Connection(dctx, has_standalone_channel=True)
|
||||
)
|
||||
ctx: Context[_Lifespan] = Context(dctx, lifespan=_Lifespan("app"), connection=Connection.for_loop(dctx))
|
||||
await ctx.log("debug", "hello") # pyright: ignore[reportDeprecated]
|
||||
return {}
|
||||
|
||||
|
|
@ -82,9 +79,7 @@ async def test_context_log_includes_logger_and_meta_when_supplied():
|
|||
_, c_notify = echo_handlers(crec)
|
||||
|
||||
async def server_on_request(dctx: DCtx, method: str, params: Mapping[str, Any] | None) -> dict[str, Any]:
|
||||
ctx: Context[_Lifespan] = Context(
|
||||
dctx, lifespan=_Lifespan("app"), connection=Connection(dctx, has_standalone_channel=True)
|
||||
)
|
||||
ctx: Context[_Lifespan] = Context(dctx, lifespan=_Lifespan("app"), connection=Connection.for_loop(dctx))
|
||||
await ctx.log("info", "x", logger="my.log", meta={"traceId": "t"}) # pyright: ignore[reportDeprecated]
|
||||
return {}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue