From 1d4f688ff6dbe0069e85b3ac2a4109733c7a55d3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 7 Sep 2024 15:33:56 -0500 Subject: [PATCH] Add xfail test for issue #5180 --- tests/test_web_websocket_functional.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_web_websocket_functional.py b/tests/test_web_websocket_functional.py index c553d0c1748..f1ca54abf39 100644 --- a/tests/test_web_websocket_functional.py +++ b/tests/test_web_websocket_functional.py @@ -1150,3 +1150,23 @@ async def on_shutdown(app: web.Application) -> None: assert reply.extra == "Server shutdown" assert websocket.closed is True + + +@pytest.mark.xfail(reason="close never reaches client per issue #5180") +async def test_ws_close_return_code(aiohttp_client: AiohttpClient) -> None: + """Test that the close code is returned when the server closes the connection.""" + + async def handler(request: web.Request) -> web.WebSocketResponse: + ws = web.WebSocketResponse() + await ws.prepare(request) + await ws.close() + return ws + + app = web.Application() + app.router.add_route("GET", "/", handler) + client = await aiohttp_client(app) + resp = await client.ws_connect("/") + await resp.send_str("some data") + await asyncio.sleep(0.1) + await resp.receive() + assert resp.close_code is WSCloseCode.OK