Skip to content

Commit

Permalink
fix: tests transport
Browse files Browse the repository at this point in the history
  • Loading branch information
mandrewcito committed Sep 1, 2024
1 parent 595e5fa commit 1735ea8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 6 additions & 4 deletions signalrcore/transport/websockets/websocket_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,12 @@ def on_message(self, app, raw_message):

def on_enter(self) -> None:
super(WsDisconnectedState, self).on_enter()

if self.context._on_close is not None and callable(self.context._on_close):
self.context._on_close()

try:
if self.context._on_close is not None and callable(self.context._on_close):
self.context._on_close()
except Exception as ex:
self.logger.error(ex)

if self.context.reconnection_handler is not None:
self.handle_reconnect()

Expand Down
8 changes: 8 additions & 0 deletions test/reconnection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def test_reconnect_interval_config(self):

connection.transport._ws.close(status=1000, reason="Closed".encode("utf-8"))

self.assertRaises(
HubConnectionError,
lambda: connection.send("DisconnectMe", []))

self.assertTrue(self._locks[identifier].acquire(timeout=30))

connection.stop()
Expand Down Expand Up @@ -87,6 +91,10 @@ def test_no_reconnect(self):

connection.transport._ws.close(status=1000, reason="Closed".encode("utf-8"))

self.assertRaises(
HubConnectionError,
lambda: connection.send("DisconnectMe", []))

self.assertTrue(self._locks[identifier].acquire(timeout=40)) # Released on close

# reconnecting not configured must not enqueue message
Expand Down

0 comments on commit 1735ea8

Please sign in to comment.