class_docstr: A suite of unit tests for ship_logs.py
  
  Yeah, it's a hack that these tests live in e2e tests.  But since they test python code it's
  just easier this way.
class_docstr_tok: ["A","suite","of","unit","tests","for","ship_logs.py","Yeah",",","it","'s","a","hack","that","these","tests","live","in","e2e","tests",".","But","since","they","test","python","code","it's","just","easier","this","way","."]
code: def test_stdout_stderr_ordering(self) -> None:
      # Stdout and stderr are collected on different threads, and therefore _can't_ be perfectly
      # synced.  But they should be "approximately" synced; i.e. each 1-second batch should
      # contain both log types.
      #
      # Most dev machines probably will be fine with small timeouts, but CI machines might be
      # slower and we allow up to 0.2 seconds of slop.
      timeouts = [0.001, 0.2]
      for timeout in timeouts:
          cmd = mkcmd(
              f"""
                  import sys
                  import time
                  print("1", file=sys.stdout, flush=True)
                  time.sleep({timeout})
                  print("2", file=sys.stderr, flush=True)
                  time.sleep({timeout})
                  print("3", file=sys.stdout, flush=True)
                  time.sleep({timeout})
                  print("4", file=sys.stderr, flush=True)
                  time.sleep({timeout})
                  print("5", file=sys.stdout, flush=True)
                  time.sleep({timeout})
                  print("6", file=sys.stderr, flush=True)
                  """
          )
          with ShipLogServer() as srv:
              exit_code = self.run_ship_logs(srv.master_url(), cmd)
          assert exit_code == 0, exit_code
          if "".join(srv.logs) == "1\n2\n3\n4\n5\n6\n":
              # Success
              break
          elif timeout == timeouts[-1]:
              # Failed, even on the highest timeout
              raise ValueError("".join(srv.logs))
  
imports: import io
  import json
  import logging
  import os
  import shutil
  import signal
  import socket
  import ssl
  import subprocess
  import sys
  import tempfile
  import textwrap
  import threading
  import time
  from typing import Any, List, Optional
  import pytest
label_desc: Use image node_id 5 for calling the TestShipLogs obj's underlying member method code with example usage: obj.test_stdout_stderr_ordering() without return types