Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions dev/breeze/src/airflow_breeze/commands/testing_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import sys
from collections.abc import Generator
from datetime import datetime
from functools import cache
from multiprocessing.pool import Pool
from time import sleep

Expand Down Expand Up @@ -123,8 +124,6 @@
LOW_MEMORY_CONDITION = 8 * 1024 * 1024 * 1024 # 8 GB
DEFAULT_TOTAL_TEST_TIMEOUT = 60 * 60 # 60 minutes

logs_already_dumped = False

option_skip_docker_compose_deletion = click.option(
"--skip-docker-compose-deletion",
help="Skip deletion of docker-compose instance after the test",
Expand Down Expand Up @@ -267,8 +266,8 @@ def _run_test(
notify_on_unhealthy_backend_container(
project_name=project_name, backend=shell_params.backend, output=output
)
if os.environ.get("CI") == "true" and result.returncode != 0 and not logs_already_dumped:
get_console(output=output).print(f"[error]Test failed with {result.returncode}. Dumping logs[/]")
if os.environ.get("CI") == "true" and result.returncode != 0:
get_console(output=output).print(f"[error]Test failed with {result.returncode}.[/]")
_dump_container_logs(output=output, shell_params=shell_params)
finally:
if not skip_docker_compose_down:
Expand Down Expand Up @@ -303,8 +302,9 @@ def _get_project_names(shell_params: ShellParams) -> tuple[str, str]:
return compose_project_name, project_name


@cache # Note: using functools.cache to avoid multiple dumps in the same run
def _dump_container_logs(output: Output | None, shell_params: ShellParams):
global logs_already_dumped
get_console().print("[warning]Dumping container logs[/]")
ps_result = run_command(
["docker", "ps", "--all", "--format", "{{.Names}}"],
check=True,
Expand All @@ -330,7 +330,6 @@ def _dump_container_logs(output: Output | None, shell_params: ShellParams):
check=False,
stdout=outfile,
)
logs_already_dumped = True


def _run_tests_in_pool(
Expand Down Expand Up @@ -1599,7 +1598,6 @@ def timeout_method(self, signum, frame):
get_console().print("[warning]Stopping all running containers[/]:")
self._print_all_containers()
if os.environ.get("CI") == "true":
get_console().print("[warning]Dumping container logs first[/]")
_dump_container_logs(output=None, shell_params=self.shell_params)
list_of_containers = self._get_running_containers().stdout.splitlines()
get_console().print("[warning]Attempting to send TERM signal to all remaining containers:")
Expand Down
8 changes: 8 additions & 0 deletions dev/breeze/src/airflow_breeze/params/shell_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,3 +812,11 @@ def __post_init__(self):
"[error]When using the Keycloak integration the backend must be Postgres![/]\n"
)
sys.exit(2)

def __eq__(self, other) -> bool:
if not isinstance(other, ShellParams):
return False
return self.__dict__ == other.__dict__

def __hash__(self) -> int:
return hash(str(self.__dict__))
Loading