Skip to content

Commit c019a8d

Browse files
committed
testing: _for_testing_peer_closed_connection doesn't need extra context switch
1 parent c3ff470 commit c019a8d

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

trio_websocket/_impl.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import ssl
1010
import struct
1111
import urllib.parse
12-
from typing import List, Optional
12+
from typing import List
1313

1414
import trio
1515
import trio.abc
@@ -744,10 +744,9 @@ def __init__(self, stream, ws_connection, *, host=None, path=None,
744744
# Set once a WebSocket closed handshake takes place, i.e after a close
745745
# frame has been sent and a close frame has been received.
746746
self._close_handshake = trio.Event()
747-
# When not None, set immediately upon receiving CloseConnection from peer,
748-
# followed by sleep(0) for a context switch. Used to test close race
749-
# conditions between client and server.
750-
self._for_testing_peer_closed_connection: Optional[trio.Event] = None
747+
# Set upon receiving CloseConnection from peer.
748+
# Used to test close race conditions between client and server.
749+
self._for_testing_peer_closed_connection = trio.Event()
751750

752751
@property
753752
def closed(self):
@@ -1105,9 +1104,7 @@ async def _handle_close_connection_event(self, event):
11051104
# Set _close_reason in advance, so that send_message() will raise
11061105
# ConnectionClosed during the close handshake.
11071106
self._close_reason = CloseReason(event.code, event.reason or None)
1108-
if self._for_testing_peer_closed_connection:
1109-
self._for_testing_peer_closed_connection.set()
1110-
await trio.sleep(0)
1107+
self._for_testing_peer_closed_connection.set()
11111108
await self._send(event.response())
11121109
await self._close_web_socket(event.code, event.reason or None)
11131110
self._close_handshake.set()

0 commit comments

Comments
 (0)