From 08d8d55ee0fb3a432054f8502ade02576075129e Mon Sep 17 00:00:00 2001 From: onee-only Date: Mon, 30 Dec 2024 11:48:39 +0000 Subject: [PATCH] =?UTF-8?q?=EC=BB=A4=EB=84=A5=EC=85=98=20=EB=81=8A?= =?UTF-8?q?=EA=B2=BC=EC=9D=84=20=EB=95=8C=20send=20=EC=B2=98=EB=A6=AC=20(?= =?UTF-8?q?=EC=95=84=EB=A7=88=20=EC=A7=84=EC=A7=9C=20=EC=B5=9C=EC=A2=85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conn/internal/conn.py | 6 +++--- conn/test/fixtures.py | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/conn/internal/conn.py b/conn/internal/conn.py index 90ab6a8..34ab239 100644 --- a/conn/internal/conn.py +++ b/conn/internal/conn.py @@ -1,4 +1,4 @@ -from fastapi.websockets import WebSocket, WebSocketState +from fastapi.websockets import WebSocket, WebSocketState, WebSocketDisconnect from websockets.exceptions import ConnectionClosed from message import Message from dataclasses import dataclass @@ -23,11 +23,11 @@ async def receive(self): return Message.from_str(await self.conn.receive_text()) async def send(self, msg: Message): - if self.conn.client_state == WebSocketState.DISCONNECTED: + if self.conn.application_state == WebSocketState.DISCONNECTED: return try: await self.conn.send_text(msg.to_str()) - except ConnectionClosed: + except (ConnectionClosed, WebSocketDisconnect): # 커넥션이 종료되었는데도 타이밍 문제로 인해 커넥션을 가져왔을 수 있음. return diff --git a/conn/test/fixtures.py b/conn/test/fixtures.py index f0c2c3f..bc2e2f1 100644 --- a/conn/test/fixtures.py +++ b/conn/test/fixtures.py @@ -1,6 +1,6 @@ from unittest.mock import MagicMock, AsyncMock -from fastapi.websockets import WebSocket +from fastapi.websockets import WebSocket, WebSocketState class ConnMock(): @@ -9,6 +9,7 @@ def __init__(self): self.receive_text = AsyncMock() self.send_text = AsyncMock() self.close = AsyncMock() + self.application_state = WebSocketState.CONNECTED def create_connection_mock() -> ConnMock: