Skip to content

Commit be96234

Browse files
test: add single-feed skip+message test for ReadBuffer
Exercises the case where a single feed() call both completes an oversized-message skip and delivers the next valid message. The effective_len calculation and discard logic interact non-trivially in this scenario, which was previously untested. Closes #118 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1a22ee9 commit be96234

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

tests/test_buffer.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,39 @@ def test_skip_message_recovers_from_oversized(self) -> None:
455455
assert data is not None
456456
assert data == valid_encoded
457457

458+
def test_single_feed_completes_skip_and_appends_message(self) -> None:
459+
"""118: single feed() that completes skip AND contains next valid message."""
460+
import struct
461+
462+
import pytest
463+
464+
from dqlitewire.exceptions import DecodeError
465+
466+
buf = ReadBuffer(max_message_size=64)
467+
# 200 words = 1600 bytes body, well over 64-byte limit
468+
oversized_header = struct.pack("<IBBH", 200, 0, 0, 0)
469+
470+
buf.feed(oversized_header)
471+
assert buf.has_message() is True
472+
with pytest.raises(DecodeError, match="exceeds maximum"):
473+
buf.read_message()
474+
assert buf.skip_message() is False
475+
assert buf.is_skipping
476+
477+
# Build a single payload: remaining skip bytes + valid message
478+
remaining = buf._skip_remaining
479+
valid_msg = LeaderRequest()
480+
valid_encoded = valid_msg.encode()
481+
combined = b"\xcc" * remaining + valid_encoded
482+
483+
buf.feed(combined)
484+
485+
assert not buf.is_skipping
486+
assert buf.has_message()
487+
data = buf.read_message()
488+
assert data is not None
489+
assert data == valid_encoded
490+
458491
def test_skip_oversized_across_multiple_feeds(self) -> None:
459492
"""Oversized message bytes should be discarded across multiple feed() calls.
460493

0 commit comments

Comments
 (0)