code: def test_async_actor_cancel_restart(ray_start_cluster, monkeypatch):
      """
      Verify a cancelation works if actor is restarted.
      """
      with monkeypatch.context() as m:
          # This will slow down the cancelation RPC so that
          # cancel won't succeed until a node is killed.
          m.setenv(
              "RAY_testing_asio_delay_us",
              "CoreWorkerService.grpc_server.CancelTask=3000000:3000000",
          )
          cluster = ray_start_cluster
          cluster.add_node(num_cpus=0)
          ray.init(address=cluster.address)
          node = cluster.add_node(num_cpus=1)
  
          @ray.remote(num_cpus=1, max_restarts=-1, max_task_retries=-1)
          class Actor:
              async def f(self):
                  await asyncio.sleep(10)
  
          a = Actor.remote()
          ref = a.f.remote()
          # This guarantees that a.f.remote() is executed
          ray.get(a.__ray_ready__.remote())
          ray.cancel(ref)
          cluster.remove_node(node)
          r, ur = ray.wait([ref])
          # When cancel is called, the task won't be retried anymore.
          # Since an actor is dead, in this case, it will raise
          # RayActorError.
          with pytest.raises(ray.exceptions.RayActorError):
              ray.get(ref)
  
          # This will restart actor, but task won't be retried.
          cluster.add_node(num_cpus=1)
          # Verify actor is restarted. f should be retried
          ray.get(a.__ray_ready__.remote())
          with pytest.raises(ray.exceptions.RayActorError):
              ray.get(ref)
  
imports: import asyncio
  import os
  import sys
  import time
  from collections import defaultdict
  import pytest
  import ray
  from ray._private.test_utils import SignalActor, wait_for_condition
  from ray.exceptions import TaskCancelledError
  from ray.util.state import list_tasks
label_desc: Use image node_id 7 for calling a global function with example usage: test_async_actor_cancel_restart(ray_start_cluster, monkeypatch) without return types