code: def test_out_of_order_chaining(serve_instance):
      # https://discuss.ray.io/t/concurrent-queries-blocking-following-queries/3949
  
      @ray.remote(num_cpus=0)
      class Collector:
          def __init__(self):
              self.lst = []
  
          def append(self, msg):
              self.lst.append(msg)
  
          def get(self):
              return self.lst
  
      collector = Collector.remote()
  
      @serve.deployment
      class Combine:
          def __init__(self, m1, m2):
              self.m1 = m1
              self.m2 = m2
  
          async def run(self, _id):
              return await self.m2.compute.remote(
                  self.m1.compute.remote(_id)
              )
  
      @serve.deployment(graceful_shutdown_timeout_s=0.0)
      class FirstModel:
          async def compute(self, _id):
              if _id == 0:
                  await asyncio.sleep(1000)
              print(f"First output: {_id}")
              ray.get(collector.append.remote(f"first-{_id}"))
              return _id
  
      @serve.deployment
      class SecondModel:
          async def compute(self, _id):
              print(f"Second output: {_id}")
              ray.get(collector.append.remote(f"second-{_id}"))
              return _id
  
      m1 = FirstModel.bind()
      m2 = SecondModel.bind()
      combine = Combine.bind(m1, m2)
      handle = serve.run(combine)
  
      handle.run.remote(_id=0)
      handle.run.remote(_id=1).result()
  
      assert ray.get(collector.get.remote()) == ["first-1", "second-1"]
  
imports: import asyncio
  import gc
  import sys
  import numpy
  import pytest
  import requests
  from fastapi import FastAPI
  from fastapi.responses import JSONResponse
  import ray
  from ray import serve
  from ray._private.test_utils import SignalActor
  from ray.serve.context import _get_global_client
  from ray.serve.handle import DeploymentHandle
label_desc: Use image node_id 8 for calling a global function with example usage: test_out_of_order_chaining(serve_instance) and returns: self, unknown, _id, _id