Skip to content

Commit

Permalink
Address comment: Use signal actor for async background task test
Browse files Browse the repository at this point in the history
Closes: #49451
Signed-off-by: Chi-Sheng Liu <[email protected]>
  • Loading branch information
MortalHappiness committed Mar 5, 2025
1 parent 2ff7d58 commit 8a931f4
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions python/ray/tests/test_actor_failures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,8 @@ def test_exit_actor_async_actor_nested_task(shutdown_only, tmp_path):
assert not temp_file_atexit.exists()
assert not temp_file_after_exit_actor.exists()

signal = SignalActor.remote()

@ray.remote
class AsyncActor:
def __init__(self):
Expand All @@ -1052,24 +1054,19 @@ def f():

atexit.register(f)

async def start_exit_task(self):
asyncio.create_task(self.exit())
async def start_exit_task(self, signal):
asyncio.create_task(self.exit(signal))

async def exit(self):
async def exit(self, signal):
await signal.wait.remote()
exit_actor()
# The following code should not be executed.
temp_file_after_exit_actor.touch()

a = AsyncActor.remote()
ray.get(a.__ray_ready__.remote())
with pytest.raises(ray.exceptions.RayActorError) as exc_info:
ray.get(a.start_exit_task.remote())
assert (
# Exited when task execution returns
"exit_actor()" in str(exc_info.value)
# Exited during periodical check in worker
or "User requested to exit the actor" in str(exc_info.value)
)
ray.get(a.start_exit_task.remote(signal))
ray.get(signal.send.remote())

def verify():
return temp_file_atexit.exists()
Expand Down

0 comments on commit 8a931f4

Please sign in to comment.