Skip to content

Commit

Permalink
Merge pull request #1216 from dimaqq/websockets-fix-and-remove-upper-…
Browse files Browse the repository at this point in the history
…bound

#1216

#1215 plus removal of the websockets dep uppper bound
  • Loading branch information
jujubot authored Nov 27, 2024
2 parents c452b66 + a53ce1e commit 0e6b5f7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
5 changes: 2 additions & 3 deletions juju/client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def status(self):
and connection._receiver_task.cancelled()
)

if stopped or not connection._ws.open:
if stopped or connection._ws.state is not websockets.protocol.State.OPEN:
return self.ERROR

# everything is fine!
Expand Down Expand Up @@ -357,8 +357,7 @@ async def close(self, to_reconnect: bool = False):
tasks_need_to_be_gathered.append(self._debug_log_task)
self._debug_log_task.cancel()

if self._ws and not self._ws.closed:
await self._ws.close()
await self._ws.close()

if not to_reconnect:
try:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies = [
"macaroonbakery>=1.1,<2.0",
"pyRFC3339>=1.0,<2.0",
"pyyaml>=5.1.2",
"websockets>=13.0.1,<14.0",
"websockets>=13.0.1",
"paramiko>=2.4.0",
"pyasn1>=0.4.4",
"toposort>=1.5,<2",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"macaroonbakery>=1.1,<2.0",
"pyRFC3339>=1.0,<2.0",
"pyyaml>=5.1.2",
"websockets>=13.0.1,<14.0",
"websockets>=13.0.1",
"paramiko>=2.4.0",
"pyasn1>=0.4.4",
"toposort>=1.5,<2",
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from unittest import mock

import pytest
import websockets
from websockets.exceptions import ConnectionClosed

from juju.client.connection import Connection
Expand All @@ -17,8 +18,7 @@ class WebsocketMock:
def __init__(self, responses):
super().__init__()
self.responses = deque(responses)
self.open = True
self.closed = False
self.state = websockets.protocol.State.OPEN

async def send(self, message):
pass
Expand All @@ -30,8 +30,7 @@ async def recv(self):
return json.dumps(self.responses.popleft())

async def close(self):
self.open = False
self.closed = True
pass


async def test_out_of_order():
Expand Down

0 comments on commit 0e6b5f7

Please sign in to comment.