Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix websocket connection leak #7978

Merged
merged 13 commits into from
Dec 18, 2023
Prev Previous commit
Next Next commit
speed up test
  • Loading branch information
bdraco committed Dec 18, 2023
commit a9754ea1e1c1e0a3fbaa0e06c822e5c7c3b79779
12 changes: 8 additions & 4 deletions tests/test_web_websocket.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# type: ignore
import asyncio
import time
from typing import Any
from unittest import mock

Expand Down Expand Up @@ -140,13 +141,16 @@


async def test_ping_timeout(make_request: Any) -> None:
loop = asyncio.get_running_loop()
future = loop.create_future()
req = make_request("GET", "/")
req._protocol._timeout_ceil_threshold = 0.001
ws = WebSocketResponse(heartbeat=0.001, timeout=0.001)
lowest_time = time.get_clock_info("monotonic").resolution
req._protocol._timeout_ceil_threshold = lowest_time
ws = WebSocketResponse(heartbeat=lowest_time, timeout=lowest_time)
await ws.prepare(req)
await asyncio.sleep(0.1)
ws._req.transport.close.side_effect = lambda: future.set_result(None)
await future
Dismissed Show dismissed Hide dismissed
assert ws.closed
assert len(ws._req.transport.close.mock_calls) == 1


def test_websocket_ready() -> None:
Expand Down Expand Up @@ -276,7 +280,7 @@
assert ws.closed
assert len(ws._req.transport.close.mock_calls) == 1

assert not (await ws.close(code=2, message="message2"))

Check failure

Code scanning / CodeQL

An assert statement has a side-effect Error

This 'assert' statement contains an
expression
which may have side effects.


async def test_prepare_post_method_ok(make_request: Any) -> None:
Expand Down
Loading