code: def test_cli_internal_api_background(self, tmp_path):
      parent_path = tmp_path / "gunicorn"
      parent_path.mkdir()
      pidfile_internal_api = parent_path / "pidflow-internal-api.pid"
      pidfile_monitor = parent_path / "pidflow-internal-api-monitor.pid"
      stdout = parent_path / "airflow-internal-api.out"
      stderr = parent_path / "airflow-internal-api.err"
      logfile = parent_path / "airflow-internal-api.log"
      try:
          # Run internal-api as daemon in background. Note that the wait method is not called.
          console.print(
              "[magenta]Starting airflow internal-api --daemon"
          )
          proc = subprocess.Popen(
              [
                  "airflow",
                  "internal-api",
                  "--daemon",
                  "--pid",
                  os.fspath(pidfile_internal_api),
                  "--stdout",
                  os.fspath(stdout),
                  "--stderr",
                  os.fspath(stderr),
                  "--log-file",
                  os.fspath(logfile),
              ]
          )
          assert proc.poll() is None
  
          pid_monitor = self._wait_pidfile(pidfile_monitor)
          console.print(f"[blue]Monitor started at {pid_monitor}")
          pid_internal_api = self._wait_pidfile(pidfile_internal_api)
          console.print(
              f"[blue]Internal API started at {pid_internal_api}"
          )
          console.print("[blue]Running airflow internal-api process:")
          # Assert that the internal-api and gunicorn processes are running (by name rather than pid).
          assert self._find_process(
              r"airflow internal-api --daemon", print_found_process=True
          )
          console.print("[blue]Waiting for gunicorn processes:")
          # wait for gunicorn to start
          for i in range(30):
              if self._find_process(r"^gunicorn"):
                  break
              console.print("[blue]Waiting for gunicorn to start ...")
              time.sleep(1)
          console.print("[blue]Running gunicorn processes:")
          assert self._find_all_processes(
              "^gunicorn", print_found_process=True
          )
          console.print(
              "[magenta]Internal-api process started successfully."
          )
          console.print(
              "[magenta]Terminating monitor process and expect "
              "internal-api and gunicorn processes to terminate as well"
          )
          proc = psutil.Process(pid_monitor)
          proc.terminate()
          assert proc.wait(120) in (0, None)
          self._check_processes(ignore_running=False)
          console.print(
              "[magenta]All internal-api and gunicorn processes are terminated."
          )
      except Exception:
          console.print("[red]Exception occurred. Dumping all logs.")
          # Dump all logs
          for file in parent_path.glob("*"):
              console.print(
                  f"Dumping {file} (size: {file.stat().st_size})"
              )
              console.print(file.read_text())
          raise
  
imports: from __future__ import annotations
  import os
  import subprocess
  import sys
  import time
  from unittest import mock
  import psutil
  import pytest
  from rich.console import Console
  from airflow import settings
  from airflow.cli import cli_parser
  from airflow.cli.commands import internal_api_command
  from airflow.cli.commands.internal_api_command import GunicornMonitor
  from airflow.settings import _ENABLE_AIP_44
  from tests.cli.commands._common_cli_classes import _ComonCLIGunicornTestClass
label_desc: Use image node_id 1 for calling the TestCliInternalAPI obj's underlying member method code with example usage: obj.test_cli_internal_api_background(tmp_path) without return types