feat(rerun): retain live playback and recover isolated viewer resources

This commit is contained in:
DCCONSTRUCTIONS
2026-11-04 00:42:54 +03:00
parent 669ada973f
commit 7a3c3c00b3
28 changed files with 1414 additions and 262 deletions
+117
View File
@@ -138,3 +138,120 @@ def test_closing_view_releases_capacity_without_waiting_for_resume_grace():
bridge.close()
for sub in views:
sub.thread.join(timeout=3)
def test_reloading_page_reuses_active_capacity_without_resetting_live_view():
"""Unloaded pages cannot send retire_view; their peers only detach later."""
import pytest
from k1link.viewer.node_rerun import PreviewResumeError
bridge = NodeRerunBridge()
views = []
try:
live = bridge.subscribe("other-live-window")
views.append(live)
live_batch = live.next_batch()
for index in range(6):
sub = bridge.subscribe(f"page-{index}")
views.append(sub)
batch = sub.next_batch()
assert batch and batch[1].startswith(b"RRF2")
sub.release() # Transport lost; no explicit viewport retirement.
# Two detached cursors plus the active window remain. Re-entering a
# recent view keeps its exact native recording and unacknowledged RRD.
resumed = bridge.subscribe("page-5", batch[0] - 1)
assert resumed is sub and resumed.next_batch() == batch
assert live.next_batch() == live_batch
assert len(bridge.subscribers) <= 4
with pytest.raises(RuntimeError, match="another live viewer"):
bridge.subscribe("third-active-window")
resumed.release()
with pytest.raises(PreviewResumeError, match="expired"):
bridge.subscribe("page-0", 1)
assert "page-0" not in bridge.views
finally:
bridge.close()
for sub in views:
sub.thread.join(timeout=3)
assert all(not sub.thread.is_alive() for sub in views)
def test_resuming_detached_view_cannot_exceed_active_limit():
import pytest
bridge = NodeRerunBridge()
views = []
try:
detached = bridge.subscribe("detached")
views.append(detached)
batch = detached.next_batch()
detached.release()
for name in ("active-a", "active-b"):
views.append(bridge.subscribe(name))
with pytest.raises(RuntimeError, match="another live viewer"):
bridge.subscribe("detached", batch[0] - 1)
assert not detached.delivery_lock.locked()
assert detached.next_batch() == batch
views[-1].release()
assert bridge.subscribe("detached", batch[0] - 1) is detached
detached.release()
finally:
bridge.close()
for sub in views:
sub.thread.join(timeout=3)
def test_budgeted_preview_coalesces_until_ack_without_losing_native_recording():
class Budget:
bps = 64000
bridge = NodeRerunBridge()
sub = bridge.subscribe('synthetic-budgeted-view', budget=Budget())
try:
first = sub.next_batch()
assert first and first[1].startswith(b'RRF2')
for sequence in range(1, 21):
bridge.process(points(sequence))
time.sleep(0.12)
assert sub.pending is first
assert sub.output.empty()
assert sub.snapshot()['sequence'] == 0
sub.acknowledge(first[0])
drain_until(sub, lambda: sub.snapshot()['sequence'] == 20)
assert sub.snapshot()['points'] == 1
assert not sub.closed.is_set()
finally:
bridge.close()
sub.thread.join(timeout=3)
def test_slow_cloud_keeps_full_spatial_frame_and_reports_source_demand():
from dataclasses import replace
from missioncore_plugin_sdk.media_budget import MediaBudget
budget = MediaBudget("cloud")
budget.update({
"schema": "missioncore.media-budget/v1", "allocation_bps": 4000, "ttl_ms": 3000,
})
bridge = NodeRerunBridge()
sub = bridge.subscribe('full-detail', budget=budget)
try:
initial = sub.next_batch()
first = points(1, age=0.1)
positions = tuple((i * .01, i % 10 * .2, i % 30 * .03) for i in range(4000))
first = replace(first, positions_xyz=positions, intensities=b'\x01' * 4000)
bridge.process(first)
latest = replace(first, context=points(2).context)
bridge.process(latest)
assert sub.pending == initial and sub.output.empty()
assert budget.demand_bps > 256000
sub.acknowledge(initial[0])
drain_until(sub, lambda: sub.snapshot()['sequence'] == 2)
assert sub.snapshot()['points'] == latest.point_count == 4000
assert first.positions_xyz == positions
assert not sub.closed.is_set()
finally:
bridge.close()
sub.thread.join(timeout=3)
budget.connection.close()