Skip to content

Commit ac54b83

Browse files
Pijukatelvdusek
authored andcommitted
Add test test_actor_fail_prevents_further_execution
1 parent 44d118d commit ac54b83

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/unit/actor/test_actor_lifecycle.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import asyncio
44
import contextlib
55
import json
6+
import logging
67
import sys
78
from datetime import datetime, timezone
89
from typing import TYPE_CHECKING, Any
@@ -296,3 +297,19 @@ async def handler(websocket: websockets.asyncio.server.ServerConnection) -> None
296297
# Check if all the other events are regular persist state events
297298
for event_data in persist_state_events_data:
298299
assert event_data == EventPersistStateData(is_migrating=False)
300+
301+
302+
async def test_actor_fail_prevents_further_execution(caplog: pytest.LogCaptureFixture) -> None:
303+
"""Test that calling Actor.fail() prevents further code execution in the Actor context."""
304+
caplog.set_level(logging.INFO)
305+
async with Actor:
306+
await Actor.fail(exit_code=2, exception=Exception('abc'), status_message='cde')
307+
raise RuntimeError('This should not trigger')
308+
309+
assert caplog.records[-3].levelno == logging.ERROR # type: ignore[unreachable]
310+
assert caplog.records[-3].msg == 'Actor failed with an exception'
311+
assert caplog.records[-3].exc_text == 'Exception: abc'
312+
assert caplog.records[-2].levelno == logging.INFO
313+
assert caplog.records[-2].msg == 'Exiting Actor'
314+
assert caplog.records[-1].levelno == logging.INFO
315+
assert caplog.records[-1].msg == '[Terminal status message]: cde'

0 commit comments

Comments
 (0)