code: def test_stress(shutdown_only, use_force):
      ray.init(num_cpus=1)
  
      @ray.remote
      def infinite_sleep(y):
          if y:
              while True:
                  time.sleep(1 / 10)
  
      first = infinite_sleep.remote(True)
  
      sleep_or_no = [random.randint(0, 1) for _ in range(100)]
      tasks = [infinite_sleep.remote(i) for i in sleep_or_no]
      cancelled = set()
  
      # Randomly kill queued tasks (infinitely sleeping or not).
      for t in tasks:
          if random.random() > 0.5:
              ray.cancel(t, force=use_force)
              cancelled.add(t)
  
      ray.cancel(first, force=use_force)
      cancelled.add(first)
  
      for done in cancelled:
          with pytest.raises(valid_exceptions(use_force)):
              ray.get(done, timeout=120)
  
      # Kill all infinitely sleeping tasks (queued or not).
      for indx, t in enumerate(tasks):
          if sleep_or_no[indx]:
              ray.cancel(t, force=use_force)
              cancelled.add(t)
      for indx, t in enumerate(tasks):
          if t in cancelled:
              with pytest.raises(valid_exceptions(use_force)):
                  ray.get(t, timeout=120)
          else:
              ray.get(t, timeout=120)
  
imports: import os
  import random
  import signal
  import sys
  import threading
  import _thread
  import time
  import pytest
  import ray
  from ray.exceptions import TaskCancelledError, RayTaskError, GetTimeoutError, WorkerCrashedError, ObjectLostError
  from ray._private.utils import DeferSigint
  from ray._private.test_utils import SignalActor, wait_for_condition
  from ray.util.state import list_tasks
label_desc: Use image node_id 11 for calling a global function with example usage: test_stress(shutdown_only, use_force) without return types