code: def test_wait(ray_start_regular_shared):
      @ray.remote
      def f(delay):
          time.sleep(delay)
          return
  
      object_refs = [f.remote(0), f.remote(0), f.remote(0), f.remote(0)]
      ready_ids, remaining_ids = ray.wait(object_refs)
      assert len(ready_ids) == 1
      assert len(remaining_ids) == 3
      ready_ids, remaining_ids = ray.wait(object_refs, num_returns=4)
      assert set(ready_ids) == set(object_refs)
      assert remaining_ids == []
  
      object_refs = [f.remote(0), f.remote(5)]
      ready_ids, remaining_ids = ray.wait(
          object_refs, timeout=0.5, num_returns=2
      )
      assert len(ready_ids) == 1
      assert len(remaining_ids) == 1
  
      # Verify that calling wait with duplicate object refs throws an
      # exception.
      x = ray.put(1)
      with pytest.raises(Exception):
          ray.wait([x, x])
  
      # Make sure it is possible to call wait with an empty list.
      ready_ids, remaining_ids = ray.wait([])
      assert ready_ids == []
      assert remaining_ids == []
  
      # Test semantics of num_returns with no timeout.
      obj_refs = [ray.put(i) for i in range(10)]
      (found, rest) = ray.wait(obj_refs, num_returns=2)
      assert len(found) == 2
      assert len(rest) == 8
  
      # Verify that incorrect usage raises a TypeError.
      x = ray.put(1)
      with pytest.raises(TypeError):
          ray.wait(x)
      with pytest.raises(TypeError):
          ray.wait(1)
      with pytest.raises(TypeError):
          ray.wait([1])
  
imports: import array
  import logging
  import os
  import random
  import subprocess
  import sys
  import tempfile
  import threading
  import time
  from unittest.mock import MagicMock, patch
  import pytest
  from ray._private.ray_constants import KV_NAMESPACE_FUNCTION_TABLE
  from ray._private.test_utils import client_test_enabled
  from ray.cluster_utils import Cluster, cluster_not_supported
  from ray.exceptions import GetTimeoutError, RayTaskError
  from ray.tests.client_test_utils import create_remote_signal_actor
label_desc: Use image node_id 19 for calling a global function with example usage: test_wait(ray_start_regular_shared) without return types