Server isolation and detailed errors

Isolated the JsonServer to server.py inside protocols/json

Added specific errors for server startup timeout and server startup
failed

Refactored errors for Core to CoreError generic and refactored
StateError to CoreStateMismatchError derived from CoreError
This commit is contained in:
h3cx committed 2026-08-03 17:17:33 +01:00
1 parent 321ccb178e
commit 482c093f38
11 files changed
+418 -65

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
import pytest
from dynalab_core import Core
from dynalab_core.config import CoreConfig
from dynalab_core.errors import JsonServerStartupError, JsonServerTimeoutError
from test.common import find_available_port
def test_json_server_raises_timeout_error() -> None:
port = find_available_port(8765)
core = Core(CoreConfig(port=port))
core._json_server._debug_timeout_test = True
core._json_server._timeout = 0.01
try:
with pytest.raises(JsonServerTimeoutError):
core.start()
finally:
core.stop()
def test_json_server_raises_startup_error() -> None:
port = find_available_port(8765)
core1 = Core(CoreConfig(port=port))
core2 = Core(CoreConfig(port=port))
core1.start()
try:
with pytest.raises(JsonServerStartupError):
core2.start()
finally:
core1.stop()
core2.stop()