Skip to content

Commit

Permalink
Improve actor test fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Dec 21, 2024
1 parent 0547d44 commit 3c42592
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions python/lvmecp/plc.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ async def notifier(value: int, labels: str, command: Command | None = None):
# Allow for 3 seconds for broadcast. This is needed because the PLC
# starts before the actor and for the first message the exchange is
# not yet available.
n_tries = 0
elapsed: float = 0
while actor.connection.connection is None:
n_tries += 1
if n_tries >= 3:
return None
await asyncio.sleep(1)
elapsed += 0.01

Check warning on line 49 in python/lvmecp/plc.py

View check run for this annotation

Codecov / codecov/patch

python/lvmecp/plc.py#L49

Added line #L49 was not covered by tests
if elapsed > 3:
return
await asyncio.sleep(0.01)

Check warning on line 52 in python/lvmecp/plc.py

View check run for this annotation

Codecov / codecov/patch

python/lvmecp/plc.py#L51-L52

Added lines #L51 - L52 were not covered by tests
actor.write(level, message)
elif command is not None:
command.write(level, message)
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ async def actor(simulator: Simulator, mocker):
mocker.patch.object(_actor.plc.hvac.modbus, "get_all", return_value={})

_actor = await setup_test_actor(_actor) # type: ignore
_actor.connection.connection = mocker.MagicMock(spec={"is_closed": False})

yield _actor

Expand Down

0 comments on commit 3c42592

Please sign in to comment.