From d049f4d1321ad1e1f5ba18063e47b723f3175f06 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sat, 7 Sep 2024 21:56:11 +0000 Subject: [PATCH] [PR #9055/11a96fcc backport][3.10] Add xfail test for issue #5180 (#9059) Co-authored-by: J. Nick Koston --- 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 2be54486ee9..5ddcdbce7d0 100644 --- a/tests/test_web_websocket_functional.py +++ b/tests/test_web_websocket_functional.py @@ -1119,3 +1119,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