Implemented handshake in json server and handoff to endpoint Endpoint handles connector handshake accept/decline then launches both its IO threads alongside its heartbeat thread which contains simple timeout logic, timeout calls connection handles to close, subsequently killing the endpoint
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
import logging
|
|
from queue import Queue
|
|
from uuid import uuid4
|
|
|
|
import pytest
|
|
|
|
from dynalab_core.protocols.constants import PROTOCOL_VERSION
|
|
from dynalab_core.protocols.endpoint import ConnectorEndpoint
|
|
from dynalab_core.protocols.errors import ConnectorEndpointQueueFullError
|
|
from dynalab_core.protocols.packets import ProtocolMessage
|
|
from dynalab_core.protocols.packets.handshake import ConnectorHello
|
|
|
|
|
|
def test_full_endpoint_queue_is_logged(caplog: pytest.LogCaptureFixture) -> None:
|
|
hello = ConnectorHello(
|
|
connector_uuid=uuid4(),
|
|
protocol_version=PROTOCOL_VERSION,
|
|
connector_name="Test connector",
|
|
connector_version="0.1.0-test",
|
|
)
|
|
endpoint = ConnectorEndpoint(hello)
|
|
endpoint._packet_ingress_queue = Queue[ProtocolMessage](maxsize=1)
|
|
|
|
with caplog.at_level(logging.DEBUG, logger="dynalab_core"):
|
|
try:
|
|
endpoint.put_ingress_packet(hello)
|
|
with pytest.raises(ConnectorEndpointQueueFullError):
|
|
endpoint.put_ingress_packet(hello)
|
|
finally:
|
|
endpoint.stop()
|
|
|
|
queue_record = next(
|
|
record
|
|
for record in caplog.records
|
|
if getattr(record, "event", None) == "endpoint.queue_full"
|
|
)
|
|
assert queue_record.levelno == logging.WARNING
|
|
assert queue_record.connector_uuid == str(hello.connector_uuid)
|
|
assert queue_record.queue_direction == "ingress"
|
|
assert queue_record.queue_size == 1
|
|
assert queue_record.queue_capacity == 1
|