Skip to content

Commit

Permalink
Merge 9cee5ff into 989fa3a
Browse files Browse the repository at this point in the history
  • Loading branch information
belm0 committed Jan 27, 2019
2 parents 989fa3a + 9cee5ff commit 07c365c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/issue_96.py
Expand Up @@ -81,7 +81,7 @@ async def handler(request):
try:
ws = await request.accept()
await ws.send_message('issue96')
await trio.sleep(random()/1000)
await ws._for_testing_peer_closed_connection.wait()
await trio.aclose_forcefully(ws._stream)
except ConnectionClosed:
pass
Expand All @@ -93,13 +93,14 @@ async def main():
ssl_context=None)
await nursery.start(serve)

for n in range(1000):
for n in range(1):
logging.info('Connection %d', n)
try:
connection = await connect_websocket(nursery, 'localhost', 8000,
'/', use_ssl=False)
await connection.get_message()
await connection.aclose()
await trio.sleep(.1)
except ConnectionClosed:
pass

Expand Down
5 changes: 5 additions & 0 deletions trio_websocket/_impl.py
Expand Up @@ -545,6 +545,9 @@ def __init__(self, stream, wsproto, *, path=None,
# Set once a WebSocket closed handshake takes place, i.e after a close
# frame has been sent and a close frame has been received.
self._close_handshake = trio.Event()
# Set immediately upon receiving closed event from peer. Used to
# test close race conditions between client and server.
self._for_testing_peer_closed_connection = trio.Event()

@property
def closed(self):
Expand Down Expand Up @@ -808,6 +811,8 @@ async def _handle_connection_closed_event(self, event):
:param event:
'''
self._for_testing_peer_closed_connection.set()
await trio.sleep(0)
await self._write_pending()
await self._close_web_socket(event.code, event.reason or None)
self._close_handshake.set()
Expand Down

0 comments on commit 07c365c

Please sign in to comment.