Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions socketshark/backend/websockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def ping_timeout_handler(self, ping: asyncio.Future[None]) -> bool:
# If we haven't received a pong after sleeping for `ping_timeout`,
# consider the connection broken and close it.
if not ping.done():
self.session.log.warn("ping timeout")
self.session.log.warning("ping timeout")
await self.close()
return True

Expand Down Expand Up @@ -80,7 +80,7 @@ async def consumer_handler(self) -> None:
try:
data = json.loads(event)
except json.decoder.JSONDecodeError:
self.session.log.warn("received invalid json")
self.session.log.warning("received invalid json")
await self.send(
ClientMessage(
{
Expand All @@ -102,7 +102,7 @@ async def send(self, event: ClientMessage) -> None:
try:
await self.websocket.send(json.dumps(event))
except websockets.ConnectionClosed:
self.session.log.warn("attempted to send to closed socket")
self.session.log.warning("attempted to send to closed socket")

async def close(self) -> None:
await self.websocket.close()
Expand Down Expand Up @@ -143,7 +143,7 @@ async def serve(
# calling close() but before this callback was executed, close
# them immediately.
if self._closed:
self.shark.log.warn(
self.shark.log.warning(
"dropped connection", remote=websocket.remote_address
)
return
Expand Down
4 changes: 2 additions & 2 deletions socketshark/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ async def _ping_handler(self, redis_connection: RedisConnection) -> None:
ping = redis_connection.redis.ping()
wait = asyncio.ensure_future(asyncio.sleep(ping_timeout))

done, pending = await asyncio.wait(
_, pending = await asyncio.wait(
[ping, wait], return_when=asyncio.FIRST_COMPLETED
)

if ping and ping in pending:
# Ping timeout
ping.cancel()
self.shark.log.warn("redis ping timeout")
self.shark.log.warning("redis ping timeout")
self._stop = True
break

Expand Down
8 changes: 4 additions & 4 deletions socketshark/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def on_client_event(self, data: ClientEventData) -> None:
"""
if not self.active:
# Event was received while the WebSocket is about to close.
self.log.warn("inactive client event ignored", data=data)
self.log.warning("inactive client event ignored", data=data)
return

self.log.debug("client event", data=data)
Expand Down Expand Up @@ -104,7 +104,7 @@ async def on_service_event(
return

if "subscription" not in data or "data" not in data:
self.log.warn("invalid service event", data=data)
self.log.warning("invalid service event", data=data)
return

subscription_name = data["subscription"]
Expand All @@ -122,7 +122,7 @@ async def on_service_event(
raw_published_at
)
except ValueError:
self.log.warn(
self.log.warning(
"invalid published_at format",
published_at=raw_published_at,
)
Expand Down Expand Up @@ -209,5 +209,5 @@ async def unsubscribe_all(self) -> None:
Force-unsubscribe all subscriptions of the session.
"""
while self.subscriptions:
name, subscription = self.subscriptions.popitem()
_, subscription = self.subscriptions.popitem()
await subscription.force_unsubscribe()
9 changes: 4 additions & 5 deletions socketshark/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def _should_deliver_message_throttle(
last_throttle = self.throttle_state.get(key)
now = time.time()
if last_throttle:
ts_last_msg_sent, pending_msg, task = last_throttle
ts_last_msg_sent, _, task = last_throttle
if task: # We'll update the message and let the task send it.
self.throttle_state[key] = (ts_last_msg_sent, data, task)
return False
Expand Down Expand Up @@ -500,17 +500,16 @@ async def message(self, event: "Event") -> None:
message_data = event.data.get("data")

result = await self.on_message(message_data)
if "data" in result:
if event:
await event.send_ok(result["data"])
if "data" in result and event:
await event.send_ok(result["data"])

async def cleanup_subscription(self) -> None:
await self.shark.service_receiver.delete_subscription(
self.session, self.name
)

for throttle in self.throttle_state.values():
ts_last_msg_sent, pending_msg, task = throttle
task = throttle[2]
if task:
task.cancel()

Expand Down
10 changes: 5 additions & 5 deletions socketshark/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,26 @@ def _get_rate_limit_wait(
if 0 <= new_wait <= max_wait:
wait = new_wait
elif new_wait > max_wait:
log.warn(
log.warning(
"rate reset value too high",
name=header_name,
value=header_value,
)
wait = max_wait
else:
log.warn(
log.warning(
"invalid rate reset value",
name=header_name,
value=header_value,
)
except ValueError:
log.warn(
log.warning(
"invalid rate reset value",
name=header_name,
value=header_value,
)
else:
log.warn(
log.warning(
"got a 429 but no rate limit reset header found in response",
)
return wait
Expand All @@ -81,7 +81,7 @@ def _scrub_url(url: str) -> str:
# so can't easily use _replace to get rid of password
# and then call urlunsplit to reconstruct url.
_, _, hostinfo = url_parts.netloc.rpartition("@")
scrubbed_netloc = f"*****:*****@{hostinfo}" # noqa: E231
scrubbed_netloc = f"*****:*****@{hostinfo}"
scrubbed_url_parts = url_parts._replace(netloc=scrubbed_netloc)
return urlunsplit(scrubbed_url_parts)

Expand Down
5 changes: 3 additions & 2 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def current_event_loop():
asyncio.set_event_loop(None)


class MockClient: # noqa SIM119
class MockClient:
def __init__(self, shark):
self.log = []
self.session = Session(shark, self)
Expand Down Expand Up @@ -1213,7 +1213,8 @@ async def test_subscription_periodic_heartbeat(self):
await asyncio.sleep(0.2)
mock_responses.assert_called_once()
await asyncio.sleep(0.2)
assert len(list(mock_responses.requests.values())[0]) == 2
captured_requests = next(iter(mock_responses.requests.values()))
assert len(captured_requests) == 2

await shark.shutdown()

Expand Down
40 changes: 20 additions & 20 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.