Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tannermpeterson committed Jun 6, 2023
1 parent 62d4b4b commit 65e4255
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/mantarray_desktop_app/sub_processes/mc_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,12 @@ def _dump_stim_packet(self, well_statuses: NDArray[(2, Any), int]) -> None:
self._has_stim_packet_been_sent = True

def _handle_beacon_tracking(self) -> None:
if self._time_of_last_beacon_secs is None:
if (
self._time_of_last_beacon_secs is None
or self._is_waiting_for_reboot
or self._is_updating_firmware
or self._is_setting_nickname
):
return
secs_since_last_beacon_received = _get_secs_since_last_beacon(self._time_of_last_beacon_secs)
if (
Expand All @@ -1237,12 +1242,7 @@ def _handle_beacon_tracking(self) -> None:
)
self._send_handshake(board_idx)
self._handshake_sent_after_beacon_missed = True
elif (
secs_since_last_beacon_received >= SERIAL_COMM_STATUS_BEACON_TIMEOUT_SECONDS
and not self._is_waiting_for_reboot
and not self._is_updating_firmware
and not self._is_setting_nickname
):
elif secs_since_last_beacon_received >= SERIAL_COMM_STATUS_BEACON_TIMEOUT_SECONDS:
raise SerialCommStatusBeaconTimeoutError()

def _handle_command_tracking(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/mc_comm/test_board_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ def test_McCommunicationProcess__does_not_check_for_overdue_status_beacons_after
# run mc_process to sent reboot command and simulator to start reboot
invoke_process_run_and_check_errors(mc_process)
invoke_process_run_and_check_errors(simulator)
# run mc_process again to make sure status beacon time is checked but no error is raised
assert mocked_get_secs.call_count == 1
# run mc_process again to make sure status beacon time is not checked
assert mocked_get_secs.call_count == 0


def test_McCommunicationProcess__raises_error_if_reboot_takes_longer_than_maximum_reboot_period(
Expand Down
17 changes: 14 additions & 3 deletions tests/mc_comm/test_serial_comm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import copy
import logging
from random import randint

from mantarray_desktop_app import create_data_packet
Expand Down Expand Up @@ -31,6 +32,7 @@
from mantarray_desktop_app.exceptions import SerialCommCommandProcessingError
from mantarray_desktop_app.sub_processes import mc_comm
import pytest
from src.mantarray_desktop_app.constants import SERIAL_COMM_STATUS_BEACON_PERIOD_SECONDS
from stdlib_utils import invoke_process_run_and_check_errors

from ..fixtures import fixture_patch_print
Expand Down Expand Up @@ -349,25 +351,34 @@ def test_McCommunicationProcess__raises_error_if_command_response_not_received_w
invoke_process_run_and_check_errors(mc_process)


def test_McCommunicationProcess__raises_error_if_status_beacon_not_received_in_allowed_period_of_time(
def test_McCommunicationProcess__handles_missed_beacons_correctly(
four_board_mc_comm_process_no_handshake,
mantarray_mc_simulator_no_beacon,
mocker,
patch_print,
):
mc_process = four_board_mc_comm_process_no_handshake["mc_process"]
to_main_queue = four_board_mc_comm_process_no_handshake["board_queues"][0][1]

set_connection_and_register_simulator(
four_board_mc_comm_process_no_handshake, mantarray_mc_simulator_no_beacon
)

# patch so next iteration of mc_process will hit beacon timeout
mocker.patch.object(
mc_comm,
"_get_secs_since_last_beacon",
autospec=True,
return_value=SERIAL_COMM_STATUS_BEACON_TIMEOUT_SECONDS,
side_effect=[SERIAL_COMM_STATUS_BEACON_PERIOD_SECONDS + 1, SERIAL_COMM_STATUS_BEACON_TIMEOUT_SECONDS],
)

invoke_process_run_and_check_errors(mc_process)
confirm_queue_is_eventually_of_size(to_main_queue, 1)
assert to_main_queue.get(timeout=QUEUE_CHECK_TIMEOUT_SECONDS) == {
"communication_type": "log",
"log_level": logging.INFO,
"message": "Status Beacon overdue. Sending handshake now to prompt a response.",
}

with pytest.raises(SerialCommStatusBeaconTimeoutError):
invoke_process_run_and_check_errors(mc_process)

Expand Down

0 comments on commit 65e4255

Please sign in to comment.