test(discord): bind the "0 disables event-silence" half of the knob test

The zero-knob test only asserted that ack_stale still trips with the knob
at 0. Because _read_websocket_health evaluates ack age before the
event-silence dimension, the test stayed green even with the
`_event_max_silence_seconds > 0` guard deleted: it never observed the
stale stamp being ignored. Assert (True, "healthy") with knob=0, a stale
stamp and a green transport first, then make the ACK stale and keep the
ack_stale assertion. Dropping the guard now fails this test.

Also correct the on_socket_event_type comment: discord.py dispatches
socket_event_type before the op-code switch but only for a non-null `t`;
heartbeat ACK frames carry `t: null`, they do not "return before" it.
This commit is contained in:
kshitijk4poor
2026-09-15 01:16:30 +05:30
committed by kshitij
parent 909731dc71
commit 7959e3b0ff
2 changed files with 13 additions and 4 deletions

View File

@@ -1287,9 +1287,10 @@ class DiscordAdapter(DiscordMediaMixin, BasePlatformAdapter):
# ``socket_event_type`` for every parsed DISPATCH frame on every connection and it
# is NOT gated behind ``enable_debug_events`` (unlike ``on_socket_raw_receive`` —
# verified against discord.py 2.7.1 ``gateway.py``: ``received_message`` calls
# ``self._dispatch('socket_event_type', event)`` before the op-code switch).
# Heartbeat ACKs return before that dispatch, so an ACKing-but-deaf socket leaves
# this stamp frozen while every transport-side check reads healthy.
# ``self._dispatch('socket_event_type', event)`` before the op-code switch, gated
# on a non-null ``t``). Heartbeat ACK frames carry ``t: null`` and skip that
# dispatch, so an ACKing-but-deaf socket leaves this stamp frozen while every
# transport-side check reads healthy.
adapter_self._last_dispatched_event_monotonic = time.perf_counter()
@self._client.event

View File

@@ -111,9 +111,17 @@ async def test_zero_silence_bound_disables_only_that_dimension(monkeypatch):
await _connect(adapter, monkeypatch, _dispatching_bot)
bot = adapter._client
_transport_healthy(bot, ack_age=120.0)
adapter._last_dispatched_event_monotonic = time.perf_counter() - 1000.0
# Knob at 0: a stale stamp alone must read healthy (the dimension is off),
# with every transport-side sample green.
_transport_healthy(bot)
assert adapter._read_websocket_health(bot) == (True, "healthy")
# Same stale stamp, now with a stale heartbeat ACK: the transport guards
# still trip, and only the ack-age dimension is named.
_transport_healthy(bot, ack_age=120.0)
await _wait_until(lambda: handler.await_count, "probe did not run with the knob at 0", timeout=8.0)
assert adapter._fatal_error_code == "discord_websocket_health_stale"
assert "ack_stale" in (adapter._fatal_error_message or "")