File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 33import asyncio
44import contextlib
55import json
6+ import logging
67import sys
78from datetime import datetime , timezone
89from 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'
You can’t perform that action at this time.
0 commit comments