fix(sfm): the Series-3 header walk fails loudly, and listing uses the normal timeout
One lost 1F reply made the list return 1 of 3 events as a 200, and on a
download gave a false 404. The list also ran on the 120 s download
timeout, so each lost reply stalled the walk 120 s with the unit locked.
- get_events() strict mode (headers_only, or only_key): a lost 0A reply,
a lost 1F(browse) reply on the success path and on the partial-record
path all re-raise their ProtocolError; a 1F that hands back a key
already walked raises ProtocolError("event chain did not advance ...").
Legacy calls (none of the new options) behave exactly as before --
pinned by tests of the same three faults under get_events().
- Series3Adapter.list_events runs on the default timeout (10 s on TCP);
download_event keeps 120 s.
- FakeProto gains optional lost-reply injection; its default is unchanged.
The repeat-key guard sits at the loop head, which is reached only for a
non-null key -- equivalent to checking each 1F's key, in one place.
Read-only; nothing new on the wire. No codec, store or DB change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
1 parent
01b9188f25
commit
59dff06f1c
4 files changed
+97
-3
No files matched your search
@@ -11,6 +11,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
import minimateplus.client as mc # noqa: E402
|
||||
from minimateplus.client import MiniMateClient # noqa: E402
|
||||
from minimateplus.models import Timestamp # noqa: E402
|
||||
from minimateplus.protocol import ProtocolError # noqa: E402
|
||||
|
||||
END = b"\x00" * 8
|
||||
KEYS = [bytes.fromhex(k) for k in ("01110000", "0111245a", "01114290")]
|
||||
@@ -200,3 +201,69 @@ def test_a_target_whose_0c_reply_was_lost_gets_no_5a(client):
|
||||
ev = client(proto).download_event_by_key(KEYS[1], expected_timestamp="2026-10-02T09:30:15")
|
||||
assert [c for c in proto.calls if c[0] == "5A"] == []
|
||||
assert ev is not None and ev.timestamp is None and ev._a5_frames is None
|
||||
|
||||
|
||||
# ── the strict walk: listing and one-event download fail loudly ───────────────
|
||||
# A lost reply must not become a short list (200) or a false 404.
|
||||
|
||||
def test_a_lost_1f_reply_fails_the_list_rather_than_shortening_it(client):
|
||||
lost = ProtocolError("no reply to 1F")
|
||||
with pytest.raises(ProtocolError) as ei:
|
||||
client(FakeProto(fail={("1F-browse", 2): lost})).list_event_headers()
|
||||
assert ei.value is lost
|
||||
|
||||
|
||||
def test_a_lost_1f_reply_fails_the_download_rather_than_reporting_no_event(client):
|
||||
lost = ProtocolError("no reply to 1F")
|
||||
proto = FakeProto(fail={("1F-browse", 2): lost})
|
||||
with pytest.raises(ProtocolError) as ei:
|
||||
client(proto).download_event_by_key(KEYS[2])
|
||||
assert ei.value is lost
|
||||
assert [c for c in proto.calls if c[0] == "5A"] == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("walk", ["list", "download"])
|
||||
def test_a_lost_0a_reply_fails_the_walk(client, walk):
|
||||
lost = ProtocolError("no reply to 0A")
|
||||
c = client(FakeProto(fail={("0A", 2): lost}))
|
||||
with pytest.raises(ProtocolError) as ei:
|
||||
c.list_event_headers() if walk == "list" else c.download_event_by_key(KEYS[2])
|
||||
assert ei.value is lost
|
||||
|
||||
|
||||
def test_a_lost_1f_reply_after_a_partial_record_fails_the_list(client):
|
||||
lost = ProtocolError("no reply to 1F")
|
||||
with pytest.raises(ProtocolError) as ei:
|
||||
client(FakeProto(partial={KEYS[1]}, fail={("1F-browse", 2): lost})).list_event_headers()
|
||||
assert ei.value is lost
|
||||
|
||||
|
||||
@pytest.mark.parametrize("walk", ["list", "download"])
|
||||
def test_a_chain_that_does_not_advance_fails_the_walk(client, walk):
|
||||
proto = FakeProto(keys=[KEYS[0], KEYS[1], KEYS[0]])
|
||||
c = client(proto)
|
||||
with pytest.raises(ProtocolError, match="did not advance.*01110000"):
|
||||
c.list_event_headers() if walk == "list" else c.download_event_by_key(KEYS[2])
|
||||
assert proto.calls.count(("0A", KEYS[0])) == 1 # stopped before re-reading it
|
||||
|
||||
|
||||
# ── ... while legacy get_events() keeps doing exactly what it did ────────────
|
||||
|
||||
def test_legacy_get_events_still_returns_what_it_read_when_a_1f_reply_is_lost(client):
|
||||
proto = FakeProto(fail={("1F-browse", 2): ProtocolError("no reply to 1F")})
|
||||
events = client(proto).get_events()
|
||||
assert [e._waveform_key for e in events] == KEYS[:2]
|
||||
assert _subs(proto) == ["1E"] + _LEGACY_PER_EVENT * 2
|
||||
|
||||
|
||||
def test_legacy_get_events_still_skips_an_event_whose_0a_reply_is_lost(client):
|
||||
proto = FakeProto(fail={("0A", 2): ProtocolError("no reply to 0A")})
|
||||
events = client(proto).get_events()
|
||||
assert [e._waveform_key for e in events] == [KEYS[0], KEYS[2]]
|
||||
assert _subs(proto) == ["1E"] + _LEGACY_PER_EVENT + ["0A", "1F"] + _LEGACY_PER_EVENT
|
||||
|
||||
|
||||
def test_legacy_get_events_still_walks_a_repeated_key(client):
|
||||
proto = FakeProto(keys=[KEYS[0], KEYS[1], KEYS[0]])
|
||||
events = client(proto).get_events()
|
||||
assert [e._waveform_key for e in events] == [KEYS[0], KEYS[1], KEYS[0]]
|
||||
Reference in new issue
Block a user