fixed commetn from songxiao

This commit is contained in:
ykcheungab
2026-09-25 17:46:37 +08:00
parent 6effe74172
commit 12781854ca
56 changed files with 4935 additions and 419 deletions
+80
View File
@@ -410,6 +410,86 @@ def test_a_file_that_yields_no_frames_ends_the_session_with_an_error(monkeypatch
_restore(saved)
def test_a_paused_worker_stops_producing_but_keeps_the_device_open():
"""Pause is not stop: compute stops, the capture keeps running.
It lives in this file because the fake device that can answer the question (does the
source keep publishing while the loop takes no frame?) is the harness above.
"""
from orisys_app_shared.acquisition.sdk_worker import SdkAcquisitionWorker
CREATED.clear()
saved = _install()
worker = SdkAcquisitionWorker()
packets: list = []
lock = threading.Lock()
def sink(packet) -> None:
with lock:
packets.append(packet)
try:
worker.add_sink(sink)
worker.start(0, config_ref=BOX_CONFIG)
time.sleep(0.4)
before = len(packets)
assert before > 0, "the fake device produced nothing to pause"
assert not worker.paused
worker.pause()
assert worker.paused
time.sleep(0.4)
during = len(packets)
# The frames the source published across the pause: the device is demonstrably
# alive, which is what makes this different from ``stop``.
source_seq_at_pause = CREATED[-1].capture_source.status.last_seq
assert during == before, (
f"a paused worker emitted {during - before} packet(s): the computation was "
"supposed to stop"
)
worker.resume()
assert not worker.paused
time.sleep(0.4)
after = len(packets)
assert after > during, "the worker did not resume producing packets"
assert CREATED[-1].capture_source.status.last_seq > source_seq_at_pause, (
"the capture source stopped publishing while paused — the device was released "
"or the reader was starved, and neither is what pause means"
)
# Resuming continues from the newest frame rather than replaying the pause: the
# packet that follows the pause is dated after it, not before.
assert float(packets[after - 1].mono_t) > 0.0
stop_requests = getattr(worker, "_stop").is_set()
assert not stop_requests, "pausing must not set the stop flag"
worker.stop(wait=True)
finally:
_restore(saved)
def test_a_new_session_starts_unpaused():
"""Pausing is a statement about one session, not a sticky property of the device."""
from orisys_app_shared.acquisition.sdk_worker import SdkAcquisitionWorker
CREATED.clear()
saved = _install()
worker = SdkAcquisitionWorker()
try:
worker.add_sink(lambda _packet: None)
worker.start(0, config_ref=BOX_CONFIG)
time.sleep(0.3)
worker.pause()
assert worker.paused
worker.stop(wait=True)
assert not worker.paused, "stop cleared the pause flag"
worker.start(0, config_ref=BOX_CONFIG)
assert not worker.paused, "the next session started paused"
worker.stop(wait=True)
finally:
_restore(saved)
if __name__ == "__main__": # pragma: no cover - manual runner
failures = 0
for name, function in sorted(globals().items()):