Skip to content

Commit

Permalink
change to moz_ping, add new method to test low level ping and await f…
Browse files Browse the repository at this point in the history
…uture in test
  • Loading branch information
taddes committed Apr 16, 2024
1 parent f968557 commit 0758445
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
17 changes: 14 additions & 3 deletions tests/integration/async_push_test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
45 changes: 30 additions & 15 deletions tests/integration/test_integration_all_rust.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Rust Connection and Endpoint Node Integration Tests."""

import asyncio
import base64
import copy
import json
Expand All @@ -25,6 +26,7 @@
import psutil
import pytest
import twisted.internet.base
import websockets
from cryptography.fernet import Fernet
from jose import jws

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 0758445

Please sign in to comment.