Skip to content

Commit

Permalink
Add tests for frame receiver controllers
Browse files Browse the repository at this point in the history
fix typo Reciever -> Receiver
  • Loading branch information
jsouter committed Aug 29, 2024
1 parent 3f8fb82 commit c2049aa
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/odin_fastcs/odin_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from odin_fastcs.odin_adapter_controller import OdinAdapterController
from odin_fastcs.odin_data import (
FrameProcessorAdapterController,
FrameRecieverAdapterController,
FrameReceiverAdapterController,
)
from odin_fastcs.util import OdinParameter, create_odin_parameters

Expand Down Expand Up @@ -74,7 +74,7 @@ def _create_adapter_controller(
connection, parameters, f"{self.API_PREFIX}/fp"
)
case "fr":
return FrameRecieverAdapterController(
return FrameReceiverAdapterController(

Check warning on line 77 in src/odin_fastcs/odin_controller.py

View check run for this annotation

Codecov / codecov/patch

src/odin_fastcs/odin_controller.py#L76-L77

Added lines #L76 - L77 were not covered by tests
connection, parameters, f"{self.API_PREFIX}/fr"
)
case "mw":
Expand Down
2 changes: 1 addition & 1 deletion src/odin_fastcs/odin_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __decoder_parameter(parameter: OdinParameter):
self._create_attributes()


class FrameRecieverAdapterController(OdinDataAdapterController):
class FrameReceiverAdapterController(OdinDataAdapterController):
_subcontroller_label = "FR"
_subcontroller_cls = FrameReceiverController

Expand Down
154 changes: 154 additions & 0 deletions tests/input/two_node_fr_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{
"api": {
"value": 0.1,
"writeable": false,
"type": "float"
},
"module": {
"value": "OdinDataAdapter",
"writeable": false,
"type": "str"
},
"endpoints": [
{
"ip_address": {
"value": "127.0.0.1",
"writeable": false,
"type": "str"
},
"port": {
"value": 10000,
"writeable": false,
"type": "int"
}
},
{
"ip_address": {
"value": "127.0.0.1",
"writeable": false,
"type": "str"
},
"port": {
"value": 10010,
"writeable": false,
"type": "int"
}
}
],
"count": {
"value": 2,
"writeable": false,
"type": "int"
},
"update_interval": {
"value": 0.2,
"writeable": false,
"type": "float"
},
"0": {
"status": {
"status": {
"ipc_configured": true,
"decoder_configured": true,
"buffer_manager_configured": true,
"rx_thread_configured": true,
"configuration_complete": true
},
"decoder": {
"name": "DummyUDPFrameDecoder",
"status_get_count": 7,
"packets_received": 0,
"packets_lost": 0,
"packets_dropped": 0
},
"buffers": {
"total": 292,
"empty": 292,
"mapped": 0
},
"frames": {
"timedout": 0,
"received": 0,
"released": 0,
"dropped": 0
},
"timestamp": "2024-08-29T13:56:17.796578",
"error": [],
"connected": true
},
"config": {
"ctrl_endpoint": "tcp://0.0.0.0:10000",
"rx_endpoint": "inproc://rx_channel",
"frame_ready_endpoint": "tcp://127.0.0.1:10001",
"frame_release_endpoint": "tcp://127.0.0.1:10002",
"decoder_path": "/scratch/hqv85942/scratchprojects/fast2/odin-data/prefix//lib",
"decoder_type": "DummyUDP",
"decoder_config": {
"enable_packet_logging": false,
"frame_timeout_ms": 1000,
"udp_packets_per_frame": 359,
"udp_packet_size": 8000
},
"shared_buffer_name": "OdinDataBuffer",
"max_buffer_mem": 840000000,
"rx_type": "udp",
"rx_address": "0.0.0.0",
"rx_ports": "61649",
"rx_recv_buffer_size": 30000000,
"frame_count": 1953718630
}
},
"1": {
"status": {
"status": {
"ipc_configured": true,
"decoder_configured": true,
"buffer_manager_configured": true,
"rx_thread_configured": true,
"configuration_complete": true
},
"decoder": {
"name": "DummyUDPFrameDecoder",
"status_get_count": 7,
"packets_received": 0,
"packets_lost": 0,
"packets_dropped": 0
},
"buffers": {
"total": 292,
"empty": 292,
"mapped": 0
},
"frames": {
"timedout": 0,
"received": 0,
"released": 0,
"dropped": 0
},
"timestamp": "2024-08-29T13:56:17.817041",
"error": [],
"connected": true
},
"config": {
"ctrl_endpoint": "tcp://0.0.0.0:10010",
"rx_endpoint": "inproc://rx_channel",
"frame_ready_endpoint": "tcp://127.0.0.1:10011",
"frame_release_endpoint": "tcp://127.0.0.1:10012",
"decoder_path": "/scratch/hqv85942/scratchprojects/fast2/odin-data/prefix//lib",
"decoder_type": "DummyUDP",
"decoder_config": {
"enable_packet_logging": false,
"frame_timeout_ms": 1000,
"udp_packets_per_frame": 359,
"udp_packet_size": 8000
},
"shared_buffer_name": "OdinDataBuffer",
"max_buffer_mem": 840000000,
"rx_type": "udp",
"rx_address": "0.0.0.0",
"rx_ports": "61650",
"rx_recv_buffer_size": 30000000,
"frame_count": 1953718630
}
}
}
43 changes: 43 additions & 0 deletions tests/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from odin_fastcs.odin_data import (
FrameProcessorController,
FrameProcessorPluginController,
FrameReceiverController,
FrameReceiverDecoderController,
)
from odin_fastcs.util import OdinParameter

Expand Down Expand Up @@ -213,3 +215,44 @@ async def test_config_fan_sender(mocker: MockerFixture):
attr1.process.assert_called_once_with(10)
attr2.process.assert_called_once_with(10)
attr.set.assert_called_once_with(10)


@pytest.mark.asyncio
async def test_frame_reciever_controllers():
valid_non_decoder_parameter = OdinParameter(
uri=["0", "status", "buffers", "total"],
metadata={"value": 292, "type": "int", "writeable": False},
)
valid_decoder_parameter = OdinParameter(
uri=["0", "status", "decoder", "packets_dropped"],
metadata={"value": 0, "type": "int", "writeable": False},
)

invalid_decoder_parameter = OdinParameter(
uri=["0", "status", "decoder", "name"],
metadata={
"value": "DummyUDPFrameDecoder",
"type": "str",
"writeable": False,
},
)
parameters = [
valid_non_decoder_parameter,
valid_decoder_parameter,
invalid_decoder_parameter,
]
fr_controller = FrameReceiverController(
HTTPConnection("", 0), parameters, "api/0.1"
)
await fr_controller.initialise()
assert isinstance(fr_controller, FrameReceiverController)
assert valid_non_decoder_parameter in fr_controller._parameters
assert len(fr_controller._parameters) == 1
assert "DECODER" in fr_controller.get_sub_controllers()

decoder_controller = fr_controller.get_sub_controllers()["DECODER"]
assert isinstance(decoder_controller, FrameReceiverDecoderController)
assert valid_decoder_parameter in decoder_controller._parameters
assert invalid_decoder_parameter not in decoder_controller._parameters
# index, status, decoder parts removed from path
assert decoder_controller._parameters[0]._path == ["packets_dropped"]
40 changes: 37 additions & 3 deletions tests/test_introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@
import pytest
from pytest_mock import MockerFixture

from odin_fastcs.odin_data import FrameProcessorAdapterController
from odin_fastcs.odin_data import (
FrameProcessorAdapterController,
FrameProcessorController,
FrameReceiverAdapterController,
FrameReceiverController,
)
from odin_fastcs.util import create_odin_parameters

HERE = Path(__file__).parent


def test_one_node():
def test_one_node_fp():
with (HERE / "input/one_node_fp_response.json").open() as f:
response = json.loads(f.read())

parameters = create_odin_parameters(response)
assert len(parameters) == 97


def test_two_node():
def test_two_node_fp():
with (HERE / "input/two_node_fp_response.json").open() as f:
response = json.loads(f.read())

Expand All @@ -41,6 +46,35 @@ async def get_plugins(idx: int):
controller = FrameProcessorAdapterController(mock_connection, parameters, "prefix")
await controller.initialise()
assert all(fpx in controller.get_sub_controllers() for fpx in ("FP0", "FP1"))
assert all(
isinstance(fpx, FrameProcessorController)
for fpx in controller.get_sub_controllers().values()
)


def test_two_node_fr():
with (HERE / "input/two_node_fr_response.json").open() as f:
response = json.loads(f.read())

parameters = create_odin_parameters(response)
assert len(parameters) == 82


@pytest.mark.asyncio
async def test_fr_initialise(mocker: MockerFixture):
with (HERE / "input/two_node_fr_response.json").open() as f:
response = json.loads(f.read())

mock_connection = mocker.MagicMock()

parameters = create_odin_parameters(response)
controller = FrameReceiverAdapterController(mock_connection, parameters, "prefix")
await controller.initialise()
assert all(frx in controller.get_sub_controllers() for frx in ("FR0", "FR1"))
assert all(
isinstance(frx, FrameReceiverController)
for frx in controller.get_sub_controllers().values()
)


def test_node_with_empty_list_is_correctly_counted():
Expand Down

0 comments on commit c2049aa

Please sign in to comment.