code: def test_generator_wait_e2e(shutdown_only, backpressure):
      ray.init(num_cpus=8)
  
      if backpressure:
          threshold = 1
      else:
          threshold = -1
  
      @ray.remote
      def f(sleep_time):
          for i in range(2):
              time.sleep(sleep_time)
              yield i
  
      @ray.remote
      def g(sleep_time):
          time.sleep(sleep_time)
          return 10
  
      gen = [
          f.options(
              _generator_backpressure_num_objects=threshold,
          ).remote(1)
          for _ in range(4)
      ]
      ref = [g.remote(2) for _ in range(4)]
      ready, unready = [], [*gen, *ref]
      result = []
      start = time.time()
      while unready:
          ready, unready = ray.wait(
              unready, num_returns=len(unready), timeout=0.1
          )
          for r in ready:
              if isinstance(r, ObjectRefGenerator):
                  try:
                      ref = next(r)
                      result.append(ray.get(ref))
                  except StopIteration:
                      pass
                  else:
                      unready.append(r)
              else:
                  result.append(ray.get(r))
      elapsed = time.time() - start
      assert elapsed < 4
      assert 2 < elapsed
  
      assert len(result) == 12
      result = Counter(result)
      assert result[0] == 4
      assert result[1] == 4
      assert result[10] == 4
  
imports: import asyncio
  import pytest
  import numpy
  import sys
  import time
  from collections import Counter
  from starlette.responses import StreamingResponse
  from starlette.requests import Request
  from fastapi import FastAPI
  from ray import serve
  from pydantic import BaseModel
  import ray
  from ray._raylet import ObjectRefGenerator
  from ray.exceptions import WorkerCrashedError
  from ray._private.test_utils import run_string_as_driver_nonblocking
  from ray.util.state import list_actors
label_desc: Use image node_id 4 for calling a global function with example usage: test_generator_wait_e2e(shutdown_only, backpressure) and returns: int