Skip to content

Commit

Permalink
Also add an overhead entry for the entire macro
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Dec 6, 2023
1 parent 6b38f2c commit 1f4afd2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/hal/macros/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand Down
8 changes: 7 additions & 1 deletion tests/macros/test_goto_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
9 changes: 7 additions & 2 deletions tests/test_macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand All @@ -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()

0 comments on commit 1f4afd2

Please sign in to comment.