diff --git a/tests/integration/async_push_test_client.py b/tests/integration/async_push_test_client.py index 4099c669d..ed8a8eff9 100644 --- a/tests/integration/async_push_test_client.py +++ b/tests/integration/async_push_test_client.py @@ -274,17 +274,28 @@ async def get_broadcast(self, timeout=1): # pragma: no cover log.error(f"Error: {ex}") return None - async def ping(self): - """Test websocket ping.""" + async def moz_ping(self): + """Send a very small message and await response.""" if not self.ws: raise Exception("WebSocket client not available as expected.") log.debug("Send: {}") - await self.ws.ping("{}") + await self.ws.send("{}") result = await self.ws.recv() log.debug(f"Recv: {result}") return result + async def ping(self): + """Test ping/pong request and respose of websocket. + A ping may serve as a keepalive or as a check that the remote endpoint received. + """ + if not self.ws: + raise Exception("WebSocket client not available as expected.") + + log.debug("Sending Ping") + ping_future = await self.ws.ping() + return ping_future + async def ack(self, channel, version) -> None: """Acknowledge message send.""" if not self.ws: diff --git a/tests/integration/test_integration_all_rust.py b/tests/integration/test_integration_all_rust.py index 7dff29c5f..de43a17d1 100644 --- a/tests/integration/test_integration_all_rust.py +++ b/tests/integration/test_integration_all_rust.py @@ -1,5 +1,6 @@ """Rust Connection and Endpoint Node Integration Tests.""" +import asyncio import base64 import copy import json @@ -25,6 +26,7 @@ import psutil import pytest import twisted.internet.base +import websockets from cryptography.fernet import Fernet from jose import jws @@ -1359,21 +1361,34 @@ async def test_msg_limit(self): assert client.uaid != uaid await self.shut_down(client) - # @pytest.mark.asyncio - # async def test_can_ping(self): - # """Test that the client can send an active ping message and get a valid response.""" - # client = await self.quick_register() - # result = await client.ping() - # assert result == "{}" - # assert client.ws.open - # try: - # await client.ping() - # except AssertionError: - # # pinging too quickly should disconnect without a valid ping - # # repsonse - # pass - # assert not client.ws.open - # await self.shut_down(client) + @pytest.mark.asyncio + async def test_can_moz_ping(self): + """Test that the client can send a small ping message and get a valid response.""" + client = await self.quick_register() + result = await client.moz_ping() + assert result == "{}" + assert client.ws.open + try: + await client.moz_ping() + except websockets.exceptions.ConnectionClosedError: + # pinging too quickly should disconnect without a valid ping + # repsonse + pass + assert not client.ws.open + await self.shut_down(client) + + @pytest.mark.asyncio + async def test_ws_ping(self): + """Test that the client can send a ping and get expected + future that returns the expected float latency value. + """ + client = await self.quick_register() + result = await client.ping() + assert type(result) is asyncio.Future + completed_fut = await result + assert type(completed_fut) is float + assert client.ws.open + await self.shut_down(client) @pytest.mark.asyncio async def test_internal_endpoints(self):