Repository: apache/airflow
File: docker-tests/tests/docker_tests/test_docker_compose_quick_start.py (Python)

Code before:

    compose_version = None
    try:
        compose_version = docker.compose.version()
    except DockerException:
        pytest.fail("`docker compose` not available. Make sure compose plugin is installed")
    try:
        docker_version = docker.version()
    except NotImplementedError:
        docker_version = run_command(["docker", "version"], return_output=True)

    console.print("[yellow] Shutting down previous instances of quick-start docker compose")
    compose = DockerClient(compose_project_name="quick-start", compose_project_directory=tmp_dir).compose
    compose.down(remove_orphans=True, volumes=True, quiet=True)
    try:
        console.print("[yellow] Starting docker compose")
        compose.up(detach=True, wait=True, color=not os.environ.get("NO_COLOR"))
        console.print("[green] Docker compose started")

        # Before we proceed, let's make sure our DAG has been parsed
        compose.execute(service="airflow-dag-processor", command=["airflow", "dags", "reserialize"])

        # Verify API server health endpoint is accessible and returns valid response
        health_response = requests.get(
            f"http://{DOCKER_COMPOSE_HOST_PORT}/api/v2/monitor/health", timeout=30
        )
        health_response.raise_for_status()
        health_data = health_response.json()
        assert "metadatabase" in health_data

        api_request("PATCH", path=f"dags/{DAG_ID}", json={"is_paused": False})
        api_request(
            "POST",
            path=f"dags/{DAG_ID}/dagRuns",
            json={"dag_run_id": DAG_RUN_ID, "logical_date": "2020-06-11T18:00:00+00:00"},
        )

        wait_for_terminal_dag_state(dag_id=DAG_ID, dag_run_id=DAG_RUN_ID)
        dag_state = api_request("GET", f"dags/{DAG_ID}/dagRuns/{DAG_RUN_ID}").get("state")
        assert dag_state == "success"
        if os.environ.get("INCLUDE_SUCCESS_OUTPUTS", "") == "true":
            print_diagnostics(compose, compose_version, docker_version)
    except Exception:
        print_diagnostics(compose, compose_version, docker_version)
        raise
    finally:
        if not os.environ.get("SKIP_DOCKER_COMPOSE_DELETION"):
            console.print(
                "[yellow] Deleting docker compose instance (you can avoid that by passing "
                "--skip-docker-compose-deletion flag in `breeze testing docker-compose` or "
                'by setting SKIP_DOCKER_COMPOSE_DELETION environment variable to "true")'

Review comment (suggestion):
```suggestion
        health_response = api_request(
            "GET",
            path="monitor/health"
        )
```

Code after:

    compose_version = None
    try:
        compose_version = docker.compose.version()
    except DockerException:
        pytest.fail("`docker compose` not available. Make sure compose plugin is installed")
    try:
        docker_version = docker.version()
    except NotImplementedError:
        docker_version = run_command(["docker", "version"], return_output=True)

    console.print("[yellow] Shutting down previous instances of quick-start docker compose")
    compose = DockerClient(compose_project_name="quick-start", compose_project_directory=tmp_dir).compose
    compose.down(remove_orphans=True, volumes=True, quiet=True)
    try:
        console.print("[yellow] Starting docker compose")
        compose.up(detach=True, wait=True, color=not os.environ.get("NO_COLOR"))
        console.print("[green] Docker compose started")

        # Before we proceed, let's make sure our DAG has been parsed
        compose.execute(service="airflow-dag-processor", command=["airflow", "dags", "reserialize"])

        # Verify API server health endpoint is accessible and returns valid response
        health_status = api_request("GET", path="monitor/health").get("metadatabase").get("status")
        assert health_status == "healthy"

        api_request("PATCH", path=f"dags/{DAG_ID}", json={"is_paused": False})
        api_request(
            "POST",
            path=f"dags/{DAG_ID}/dagRuns",
            json={"dag_run_id": DAG_RUN_ID, "logical_date": "2020-06-11T18:00:00+00:00"},
        )

        wait_for_terminal_dag_state(dag_id=DAG_ID, dag_run_id=DAG_RUN_ID)
        dag_state = api_request("GET", f"dags/{DAG_ID}/dagRuns/{DAG_RUN_ID}").get("state")
        assert dag_state == "success"
        if os.environ.get("INCLUDE_SUCCESS_OUTPUTS", "") == "true":
            print_diagnostics(compose, compose_version, docker_version)
    except Exception:
        print_diagnostics(compose, compose_version, docker_version)
        raise
    finally:
        if not os.environ.get("SKIP_DOCKER_COMPOSE_DELETION"):
            console.print(
                "[yellow] Deleting docker compose instance (you can avoid that by passing "
                "--skip-docker-compose-deletion flag in `breeze testing docker-compose` or "
                'by setting SKIP_DOCKER_COMPOSE_DELETION environment variable to "true")'
            )
            compose.down(remove_orphans=True, volumes=True, quiet=True)
            console.print("[green]Docker compose instance deleted")
        else: