Prepared for playback engine
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
import logging
|
||||
import threading
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
from dynalab_core import Core
|
||||
from dynalab_core.config import CoreConfig
|
||||
from dynalab_core.errors import CoreStateMismatchError
|
||||
from dynalab_core.protocols.endpoint import ConnectorEndpoint
|
||||
from dynalab_core.protocols.packets.data import ValueDescriptor
|
||||
from dynalab_core.protocols.packets.handshake import ConnectorHello
|
||||
from test.common import find_available_port
|
||||
|
||||
|
||||
@@ -32,3 +37,59 @@ def test_core_cannot_start_twice(caplog: pytest.LogCaptureFixture) -> None:
|
||||
)
|
||||
assert rejection.levelno == logging.WARNING
|
||||
assert rejection.core_state == "started"
|
||||
|
||||
|
||||
def test_core_input_worker_logs_failure(
|
||||
caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
core = Core(CoreConfig(port=find_available_port(8765)))
|
||||
|
||||
def fail_routing(message: ValueDescriptor) -> None:
|
||||
raise RuntimeError("routing failed")
|
||||
|
||||
monkeypatch.setattr(core._derive_registry, "put_data", fail_routing)
|
||||
|
||||
with caplog.at_level(logging.DEBUG, logger="dynalab_core"):
|
||||
core.start()
|
||||
try:
|
||||
core._data_input_queue.put_nowait(
|
||||
ValueDescriptor(signal_id=uuid4(), value=1.0, timestamp=1)
|
||||
)
|
||||
assert core._input_worker_stopped_event.wait(1.0)
|
||||
finally:
|
||||
core.stop()
|
||||
|
||||
failures = [
|
||||
record
|
||||
for record in caplog.records
|
||||
if getattr(record, "event", None) == "core.input_worker_failed"
|
||||
]
|
||||
assert len(failures) == 1
|
||||
assert failures[0].exception_type == "RuntimeError"
|
||||
assert failures[0].message_type == "ValueDescriptor"
|
||||
assert failures[0].exc_info is not None
|
||||
|
||||
|
||||
def test_core_mode_is_shared_with_endpoints() -> None:
|
||||
core = Core(CoreConfig(port=find_available_port(8765)))
|
||||
endpoint = ConnectorEndpoint(
|
||||
ConnectorHello(
|
||||
connector_uuid=uuid4(),
|
||||
connector_name="test",
|
||||
connector_version="1.0",
|
||||
signals=[],
|
||||
),
|
||||
threading.Event(),
|
||||
threading.Event(),
|
||||
core._data_input_queue,
|
||||
core._connector_registry._core_mode,
|
||||
)
|
||||
|
||||
try:
|
||||
assert endpoint._core_mode is core._mode
|
||||
|
||||
core.set_mode("playback")
|
||||
|
||||
assert endpoint._core_mode.value == "playback"
|
||||
finally:
|
||||
core.stop()
|
||||
|
||||
Reference in New Issue
Block a user