Skip to content

Commit 8b03bec

Browse files
Pin uint64 boundary round-trips for MetadataResponse and WelcomeResponse
Existing coverage for these two responses uses a single representative value each (MetadataResponse: 1/50; WelcomeResponse: 15000). Both fields are declared uint64 on the wire; a refactor that narrowed either to int64 or int32 would still pass the one happy-path test. Add parametrised round-trips covering UINT32_MAX, high-bit mid-range, and UINT64_MAX so the wire contract is fenced. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 484b2bc commit 8b03bec

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/test_messages_responses.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ def test_roundtrip(self) -> None:
106106
decoded = WelcomeResponse.decode_body(encoded[HEADER_SIZE:])
107107
assert decoded.heartbeat_timeout == 15000
108108

109+
@pytest.mark.parametrize("heartbeat", [0, 1, 2**64 - 1])
110+
def test_roundtrip_heartbeat_boundaries(self, heartbeat: int) -> None:
111+
"""heartbeat_timeout is uint64 on the wire. Existing tests
112+
already cover 10_000 / 15_000 / 15_000_000_000 (larger than
113+
uint32); this pins the uint64 extremes so a narrowing refactor
114+
would surface here, not in a heartbeat-tied latency regression
115+
far downstream."""
116+
msg = WelcomeResponse(heartbeat_timeout=heartbeat)
117+
encoded = msg.encode()
118+
decoded = WelcomeResponse.decode_body(encoded[HEADER_SIZE:])
119+
assert decoded.heartbeat_timeout == heartbeat
120+
109121

110122
class TestDbResponse:
111123
def test_roundtrip(self) -> None:
@@ -1304,6 +1316,25 @@ def test_roundtrip(self) -> None:
13041316
assert decoded.failure_domain == 1
13051317
assert decoded.weight == 50
13061318

1319+
@pytest.mark.parametrize(
1320+
"failure_domain,weight",
1321+
[
1322+
(2**32 - 1, 2**32 - 1),
1323+
(2**63, 2**63 + 1),
1324+
(2**64 - 1, 2**64 - 1),
1325+
],
1326+
)
1327+
def test_roundtrip_uint64_boundaries(self, failure_domain: int, weight: int) -> None:
1328+
"""Both fields are declared uint64 on the wire. Pinning the high
1329+
bits protects against a future refactor that narrows either
1330+
field to int32 / int64 — a single happy-path test would still
1331+
pass with (1, 50)."""
1332+
msg = MetadataResponse(failure_domain=failure_domain, weight=weight)
1333+
encoded = msg.encode()
1334+
decoded = MetadataResponse.decode_body(encoded[HEADER_SIZE:])
1335+
assert decoded.failure_domain == failure_domain
1336+
assert decoded.weight == weight
1337+
13071338

13081339
class TestShortBodyDecoding:
13091340
"""Fixed-width response decoders must raise ``DecodeError`` on a body

0 commit comments

Comments
 (0)