fix(perception): require joint clock readiness before source activation
This commit is contained in:
@@ -4,11 +4,62 @@ from dataclasses import replace
|
||||
|
||||
import pytest
|
||||
|
||||
from k1link.perception.streaming_clock import ClockMappingError, ClockProbe, ClockWindow
|
||||
from k1link.perception.streaming_clock import (
|
||||
ClockBounds,
|
||||
ClockMappingError,
|
||||
ClockProbe,
|
||||
ClockWindow,
|
||||
)
|
||||
|
||||
BASE = 10**16 # Deliberately above IEEE754 exact-integer range.
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"fault",
|
||||
[
|
||||
None,
|
||||
"float",
|
||||
"integer",
|
||||
"plus",
|
||||
"leading",
|
||||
"negative_zero",
|
||||
"extra",
|
||||
"missing",
|
||||
"flags",
|
||||
"wide",
|
||||
"schema",
|
||||
],
|
||||
)
|
||||
def test_bounds_wire_exact_closed_and_signed(fault):
|
||||
bounds = window().add(probe())
|
||||
document = bounds.to_dict()
|
||||
if fault is None:
|
||||
assert ClockBounds.from_dict(document) == bounds
|
||||
return
|
||||
if fault == "float":
|
||||
document["measured_at_ns"] = float(bounds.measured_at_ns)
|
||||
elif fault == "integer":
|
||||
document["measured_at_ns"] = bounds.measured_at_ns
|
||||
elif fault == "plus":
|
||||
document["offset_upper_ns"] = "+1"
|
||||
elif fault == "leading":
|
||||
document["measured_at_ns"] = "0" + document["measured_at_ns"]
|
||||
elif fault == "negative_zero":
|
||||
document["offset_upper_ns"] = "-0"
|
||||
elif fault == "extra":
|
||||
document["ready"] = True
|
||||
elif fault == "missing":
|
||||
del document["samples"]
|
||||
elif fault == "flags":
|
||||
document["conditional_rate_error_envelope"] = 1
|
||||
elif fault == "wide":
|
||||
document["offset_upper_ns"] = str(2**63)
|
||||
else:
|
||||
document["schema_version"] = "old"
|
||||
with pytest.raises(ClockMappingError):
|
||||
ClockBounds.from_dict(document)
|
||||
|
||||
|
||||
def probe(number=1, *, outbound=1_000_000, inbound=2_000_000, offset=-(10**12)):
|
||||
sent = BASE + number * 100_000_000
|
||||
return ClockProbe(
|
||||
|
||||
Reference in New Issue
Block a user