Skip to content

Commit 24c7ede

Browse files
Use self.RESTART_DELAY instead of hard-coding Actor class' value
Signed-off-by: Christian Parpart <[email protected]>
1 parent 466805c commit 24c7ede

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

src/frequenz/sdk/actor/_actor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async def _delay_if_restart(self, iteration: int) -> None:
6868
# the longer the actor has been running.
6969
# Not just for the restart-delay but actually for the n_restarts counter as well.
7070
if iteration > 0:
71-
delay = Actor.RESTART_DELAY.total_seconds()
71+
delay = self.RESTART_DELAY.total_seconds()
7272
_logger.info("Actor %s: Waiting %s seconds...", self, delay)
7373
await asyncio.sleep(delay)
7474

tests/actor/test_actor.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,18 +195,6 @@ async def test_basic_actor(caplog: pytest.LogCaptureFixture) -> None:
195195
]
196196

197197

198-
def expected_wait_time(iterations: int) -> timedelta:
199-
"""Calculate the expected wait time for a given iteration.
200-
201-
Args:
202-
iterations: The iteration to calculate the wait time for.
203-
204-
Returns:
205-
The expected wait time in seconds.
206-
"""
207-
return timedelta(seconds=iterations * Actor.RESTART_DELAY.total_seconds())
208-
209-
210198
@pytest.mark.parametrize("restart_limit", [0, 1, 2, 10])
211199
async def test_restart_on_unhandled_exception(
212200
restart_limit: int, caplog: pytest.LogCaptureFixture
@@ -226,7 +214,10 @@ async def test_restart_on_unhandled_exception(
226214

227215
# NB: We're adding 1.0s to the timeout to account for the time it takes to
228216
# run, crash, and restart the actor.
229-
async with asyncio.timeout(expected_wait_time(restart_limit).total_seconds() + 1.0):
217+
expected_wait_time = timedelta(
218+
seconds=restart_limit * RaiseExceptionActor.RESTART_DELAY.total_seconds() + 1.0
219+
)
220+
async with asyncio.timeout(expected_wait_time.total_seconds()):
230221
with actor_restart_limit(restart_limit):
231222
actor = RaiseExceptionActor(
232223
channel.new_receiver(),

0 commit comments

Comments
 (0)