diff --git a/doc/news/DM-47223.feature.rst b/doc/news/DM-47223.feature.rst new file mode 100644 index 00000000..89d29399 --- /dev/null +++ b/doc/news/DM-47223.feature.rst @@ -0,0 +1 @@ +Update ``_wait_hard_point_test_ok`` method in ``MTCS`` to be compatible with concurrent executions. diff --git a/python/lsst/ts/observatory/control/maintel/mtcs.py b/python/lsst/ts/observatory/control/maintel/mtcs.py index b59b2d8d..49dcac2f 100644 --- a/python/lsst/ts/observatory/control/maintel/mtcs.py +++ b/python/lsst/ts/observatory/control/maintel/mtcs.py @@ -1311,11 +1311,14 @@ async def _wait_hard_point_test_ok(self, hp: int) -> None: self.log.info("Checking if the hard point breakaway test has passed.") - while True: + timer_task = asyncio.create_task( + asyncio.sleep(self.timeout_hardpoint_test_status) + ) + while not timer_task.done(): hp_test_state = MTM1M3.HardpointTest( ( - await self.rem.mtm1m3.evt_hardpointTestStatus.next( - flush=False, timeout=self.timeout_hardpoint_test_status + await self.rem.mtm1m3.evt_hardpointTestStatus.aget( + timeout=self.timeout_hardpoint_test_status ) ).testState[hp - 1] ) @@ -1328,6 +1331,16 @@ async def _wait_hard_point_test_ok(self, hp: int) -> None: else: self.log.info(f"Hard point {hp} test state: {hp_test_state!r}.") + try: + await self.rem.mtm1m3.evt_heartbeat.next( + flush=True, timeout=self.timeout_hardpoint_test_status + ) + except asyncio.TimeoutError: + raise RuntimeError( + f"No heartbeat received from M1M3 in the last {self.timeout_hardpoint_test_status}s" + " while waiting for hard point data information. Check CSC liveliness." + ) + async def _wait_bump_test_ok( self, actuator_id: int, primary: bool, secondary: bool ) -> None: diff --git a/python/lsst/ts/observatory/control/mock/mtcs_async_mock.py b/python/lsst/ts/observatory/control/mock/mtcs_async_mock.py index b5c64e0a..20b78e8d 100644 --- a/python/lsst/ts/observatory/control/mock/mtcs_async_mock.py +++ b/python/lsst/ts/observatory/control/mock/mtcs_async_mock.py @@ -268,6 +268,7 @@ async def setup_mtm1m3(self) -> None: "evt_detailedState.next.side_effect": self.mtm1m3_evt_detailed_state, "evt_detailedState.aget.side_effect": self.mtm1m3_evt_detailed_state, "evt_hardpointTestStatus.next.side_effect": self.mtm1m3_evt_hp_test_status, + "evt_hardpointTestStatus.aget.side_effect": self.mtm1m3_evt_hp_test_status, "evt_forceActuatorBumpTestStatus.next.side_effect": self.mtm1m3_evt_bump_test_status, "evt_forceActuatorBumpTestStatus.aget.side_effect": self.mtm1m3_evt_bump_test_status, "cmd_raiseM1M3.set_start.side_effect": self.mtm1m3_cmd_raise_m1m3, diff --git a/tests/maintel/test_mtcs.py b/tests/maintel/test_mtcs.py index 1da8c1f3..4bdaf716 100644 --- a/tests/maintel/test_mtcs.py +++ b/tests/maintel/test_mtcs.py @@ -1484,8 +1484,7 @@ async def test_run_m1m3_hard_point_test(self) -> None: timeout=self.mtcs.long_timeout, ) self.mtcs.rem.mtm1m3.evt_hardpointTestStatus.flush.assert_called() - self.mtcs.rem.mtm1m3.evt_hardpointTestStatus.next.assert_awaited_with( - flush=False, + self.mtcs.rem.mtm1m3.evt_hardpointTestStatus.aget.assert_awaited_with( timeout=self.mtcs.timeout_hardpoint_test_status, ) @@ -1500,11 +1499,23 @@ async def test_run_m1m3_hard_point_test_failed(self) -> None: timeout=self.mtcs.long_timeout, ) self.mtcs.rem.mtm1m3.evt_hardpointTestStatus.flush.assert_called() - self.mtcs.rem.mtm1m3.evt_hardpointTestStatus.next.assert_awaited_with( - flush=False, + self.mtcs.rem.mtm1m3.evt_hardpointTestStatus.aget.assert_awaited_with( timeout=self.mtcs.timeout_hardpoint_test_status, ) + async def test_run_m1m3_hard_point_test_timeout(self) -> None: + message = ( + f"No heartbeat received from M1M3 in the last {self.mtcs.timeout_hardpoint_test_status}s" + " while waiting for hard point data information. Check CSC liveliness." + ) + with unittest.mock.patch.object( + self.mtcs.rem.mtm1m3.evt_heartbeat, + "next", + side_effect=asyncio.TimeoutError, + ): + with pytest.raises(RuntimeError, match=message): + await self.mtcs.run_m1m3_hard_point_test(hp=1) + async def test_stop_m1m3_hard_point_test(self) -> None: await self.mtcs.stop_m1m3_hard_point_test(hp=1)