Skip to content

Commit ed24e39

Browse files
authored
Merge pull request #171 from xconnio/fix-leave-timeout
Wait for goodbye result before closing WebSocket connection
2 parents 51d6fff + 868e912 commit ed24e39

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ test = [
3535
"pytest",
3636
"pytest-asyncio",
3737
"ruff",
38+
"pytest-timeout",
3839
]
3940
publish = ["twine", "build"]
4041
dev = ["wampproto@git+https://github.com/xconnio/wampproto-python"]

tests/client_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import pytest
2+
3+
from xconn import Client
4+
from tests.utils import ROUTER_URL, REALM
5+
6+
7+
@pytest.mark.timeout(10)
8+
@pytest.mark.parametrize("url", ROUTER_URL)
9+
def test_session_leave(url: str):
10+
client = Client()
11+
session = client.connect(url, REALM)
12+
session.leave()

tests/interop_test.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33

44
from xconn import Client, AsyncClient
55
from xconn.types import Result, Event, Invocation
6+
from tests.utils import ROUTER_URL, REALM
67

7-
XCONN_URL = "ws://localhost:8080/ws"
8-
CROSSBAR_URL = "ws://localhost:8081/ws"
9-
REALM = "realm1"
108
PROCEDURE_ADD = "io.xconn.backend.add2"
119

12-
ROUTER_URL = [XCONN_URL, CROSSBAR_URL]
1310
SERIALIZERS = [serializers.JSONSerializer(), serializers.CBORSerializer(), serializers.MsgPackSerializer()]
1411
AUTHENTICATORS = [
1512
auth.AnonymousAuthenticator(""),

tests/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
XCONN_URL = "ws://localhost:8080/ws"
2+
CROSSBAR_URL = "ws://localhost:8081/ws"
3+
ROUTER_URL = [XCONN_URL, CROSSBAR_URL]
4+
REALM = "realm1"

xconn/session.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,10 @@ def leave(self):
245245
goodbye = messages.Goodbye(messages.GoodbyeFields({}, uris.CLOSE_REALM))
246246
data = self.session.send_message(goodbye)
247247
self.base_session.send(data)
248-
self.base_session.close()
249-
250-
return self.goodbye_request.result(timeout=10)
248+
try:
249+
self.goodbye_request.result(timeout=10)
250+
finally:
251+
self.base_session.close()
251252

252253
def ping(self, timeout: int = 10) -> float:
253254
return self.base_session.transport.ping(timeout)

0 commit comments

Comments
 (0)