fix: backend unavailable test — use free port + ws.close(timeout=2s)
- Use _free_port() instead of hardcoded 19999 (avoids CI port conflicts) - Add timeout=2.0 to ws.close() so close handshake never blocks >2s
This commit is contained in:
@@ -72,7 +72,7 @@ async def _ws_proxy(request: web.Request, host: str, port: int) -> web.WebSocket
|
|||||||
)
|
)
|
||||||
except (OSError, asyncio.TimeoutError) as exc:
|
except (OSError, asyncio.TimeoutError) as exc:
|
||||||
logger.error("Cannot connect to LSP on %s:%d — %s", host, port, exc)
|
logger.error("Cannot connect to LSP on %s:%d — %s", host, port, exc)
|
||||||
await ws.close(code=1011, message=b"LSP backend unavailable")
|
await ws.close(code=1011, message=b"LSP backend unavailable", timeout=2.0)
|
||||||
return ws
|
return ws
|
||||||
|
|
||||||
async def ws_to_tcp():
|
async def ws_to_tcp():
|
||||||
|
|||||||
@@ -192,7 +192,9 @@ async def test_fake_client_receives_completion_capabilities(proxy_base_url):
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_ws_backend_unavailable_closes_cleanly(proxy_base_url, monkeypatch):
|
async def test_ws_backend_unavailable_closes_cleanly(proxy_base_url, monkeypatch):
|
||||||
"""If pylsp is unreachable, WebSocket should close gracefully (not crash)."""
|
"""If pylsp is unreachable, WebSocket should close gracefully (not crash)."""
|
||||||
monkeypatch.setattr("ilsp.server.PYTHON_LSP_PORT", 19999)
|
# Use _free_port() to guarantee nothing is listening (avoids CI port 19999 collisions)
|
||||||
|
dead_port = _free_port()
|
||||||
|
monkeypatch.setattr("ilsp.server.PYTHON_LSP_PORT", dead_port)
|
||||||
|
|
||||||
ws_url = proxy_base_url.replace("http://", "ws://") + "/python"
|
ws_url = proxy_base_url.replace("http://", "ws://") + "/python"
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
|
|||||||
Reference in New Issue
Block a user