diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 51ae730..e8156f4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -56,6 +56,8 @@ jobs: run: | pip install pytest pytest-mock pytest-asyncio pytest-cov pytest + env: + OBSERVATORY: 'APO' - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 diff --git a/src/hal/macros/macro.py b/src/hal/macros/macro.py index c3b50f5..eb65baf 100644 --- a/src/hal/macros/macro.py +++ b/src/hal/macros/macro.py @@ -365,7 +365,7 @@ async def fail_macro( self.running = False - async def run(self): + async def run(self) -> bool: """Executes the macro allowing for cancellation.""" if self.running: @@ -381,7 +381,8 @@ async def run(self): self._running_task = asyncio.create_task(self._do_run()) try: - await self._running_task + async with OverheadHelper(self, ""): + await self._running_task except asyncio.CancelledError: with suppress(asyncio.CancelledError): self._running_task.cancel() diff --git a/tests/macros/test_goto_field.py b/tests/macros/test_goto_field.py index 115d989..1c96256 100644 --- a/tests/macros/test_goto_field.py +++ b/tests/macros/test_goto_field.py @@ -65,4 +65,10 @@ async def test_goto_field_fails_tcc(goto_field_macro, mocker: MockerFixture): reply_codes = [reply.flag for reply in command.actor.mock_replies] assert "e" in reply_codes - assert command.replies[-1].message["stage_duration"][1] == "slew:reconfigure" + # Concurrent stages duration + assert command.replies[-2].message["stage_duration"][1] == "slew:reconfigure" + + # Entire macro duration + assert command.replies[-1].message["stage_duration"][0] == "goto_field" + assert command.replies[-1].message["stage_duration"][1] == "" + assert isinstance(command.replies[-1].message["stage_duration"][2], float) diff --git a/tests/test_macro.py b/tests/test_macro.py index 307d7e8..a5c768c 100644 --- a/tests/test_macro.py +++ b/tests/test_macro.py @@ -21,7 +21,9 @@ async def test_macro(actor, macro: Macro, command: HALCommandType): await macro.run() - assert len(actor.mock_replies) == 13 + assert len(actor.mock_replies) == 14 + + # This checks the first stage_duration assert command.replies.get("stage_duration") == ["macro_test", "stage1", 0.0] @@ -33,9 +35,12 @@ async def test_macro_stage_fails(actor, macro: Macro, mocker): assert macro.running is False - last_stage_status = actor.mock_replies[-2]["stage_status"] + last_stage_status = actor.mock_replies[-3]["stage_status"] assert "stage2,failed" in last_stage_status assert "cleanup,finished" in last_stage_status + last_stage_duration = actor.mock_replies[-1]["stage_duration"] + assert "macro_test,," in last_stage_duration + stage2.assert_called() cleanup.assert_called()