Skip to content

Commit

Permalink
fix tests now that websocket backend send is sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Kafonek committed Aug 11, 2022
1 parent c48668c commit 830c635
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tests/test_websocket_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from managed_service_fixtures import AppDetails, AppManager

from sending.backends.websocket import WebsocketManager
from sending.base import QueuedMessage


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -66,7 +67,7 @@ async def test_basic_send(manager: WebsocketManager):
"""
await manager.initialize()
assert manager.auth_hook is None
await manager.send(json.dumps({"type": "unauthed_echo_request", "text": "Hello plain_manager"}))
manager.send(json.dumps({"type": "unauthed_echo_request", "text": "Hello plain_manager"}))
await asyncio.wait_for(manager.next_event.wait(), 1)
reply = json.loads(manager.last_seen_message)
assert reply == {"type": "unauthed_echo_reply", "text": "Hello plain_manager"}
Expand All @@ -77,7 +78,7 @@ async def test_message_hooks(json_manager: WebsocketManager):
Test that the inbound and outbound message hooks serialize/deserialize json
"""
await json_manager.initialize()
await json_manager.send({"type": "unauthed_echo_request", "text": "Hello json_manager"})
json_manager.send({"type": "unauthed_echo_request", "text": "Hello json_manager"})
reply = await run_until_message_type(json_manager, "unauthed_echo_reply")
assert reply == {"type": "unauthed_echo_reply", "text": "Hello json_manager"}

Expand All @@ -88,7 +89,7 @@ async def test_init_hook(json_manager: WebsocketManager):
"""

async def init_hook(mgr: WebsocketManager):
await mgr.send({"type": "unauthed_echo_request", "text": "Hello init_hook"})
mgr.send({"type": "unauthed_echo_request", "text": "Hello init_hook"})

json_manager.init_hook = init_hook
await json_manager.initialize()
Expand Down Expand Up @@ -159,7 +160,7 @@ async def auth_hook(mgr: WebsocketManager):
)
await json_manager.initialize()
# test that we're authenticated on the server side
await json_manager.send({"type": "authed_echo_request", "text": "Hello auth"})
json_manager.send({"type": "authed_echo_request", "text": "Hello auth"})
reply = await run_until_message_type(json_manager, "authed_echo_reply")
assert reply == {"type": "authed_echo_reply", "text": "Hello auth"}

Expand All @@ -168,7 +169,7 @@ async def auth_hook(mgr: WebsocketManager):
resp = await client.get(f"/disconnect/{token}")
assert resp.status_code == 204

await json_manager.send({"type": "authed_echo_request", "text": "Hello auth2"})
json_manager.send({"type": "authed_echo_request", "text": "Hello auth2"})
reply = await run_until_message_type(json_manager, "authed_echo_reply")
assert reply == {"type": "authed_echo_reply", "text": "Hello auth2"}

Expand Down Expand Up @@ -202,7 +203,7 @@ async def auth_hook(self, mgr):

mgr = Sub(ws_url=websocket_server.ws_base + "/ws")
await mgr.initialize()
await mgr.send({"type": "authed_echo_request", "text": "Hello subclass"})
mgr.send({"type": "authed_echo_request", "text": "Hello subclass"})
reply = await run_until_message_type(mgr, "authed_echo_reply")
assert reply == {"type": "authed_echo_reply", "text": "Hello subclass"}
await mgr.shutdown()

0 comments on commit 830c635

Please sign in to comment.