class_docstr: Tests for horovod.runner.common.service.
code: def test_shutdown_during_request_basic_task(self):
      result_queue = queue.Queue(1)
  
      def wait_for_exit_code(client, queue):
          queue.put(client.wait_for_command_exit_code())
  
      key = secret.make_secret_key()
      service_name = "test-service"
      service = BasicTaskService(
          service_name, 0, key, nics=None, verbose=2
      )
      try:
          client = BasicTaskClient(
              service_name,
              service.addresses(),
              key,
              verbose=2,
              attempts=1,
          )
          thread = threading.Thread(
              target=wait_for_exit_code, args=(client, result_queue)
          )
  
          start = time.time()
          thread.start()  # wait for command exit code
          client.run_command("sleep 2", {})  # execute command
          time.sleep(
              0.5
          )  # give the thread some time to connect before shutdown
      finally:
          service.shutdown()  # shutdown should wait on request to finish
  
      duration = time.time() - start
      self.assertGreaterEqual(duration, 2)
  
      # we cannot call after shutdown
      with pytest.raises(
          Exception,
          match=r"^(\[[Ee]rrno 104\] Connection reset by peer)"
          r"|(\[[Ee]rrno 111\] Connection refused)$",
      ):
          client.command_result()
  
      # but still our long running request succeeded
      thread.join(1.0)
      self.assertFalse(thread.is_alive())
  
imports: import io
  import queue
  import threading
  import time
  import unittest
  import warnings
  import pytest
  from horovod.runner.common.service.task_service import BasicTaskClient, BasicTaskService
  from horovod.runner.common.util import network, secret
  from horovod.runner.util.threads import in_thread
  from horovod.runner.util.streams import Pipe
label_desc: Use image node_id 4 for calling the NetworkTests obj's underlying member method code with example usage: obj.test_shutdown_during_request_basic_task() without return types