You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by js...@apache.org on 2024/10/06 12:52:21 UTC
(airflow) branch main updated: fix fast api background process test (#42781)
This is an automated email from the ASF dual-hosted git repository.
jscheffl pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 6da1799aad2 fix fast api background process test (#42781)
6da1799aad2 is described below
commit 6da1799aad28422147607119a6cd030aeac0cc21
Author: GPK <go...@gmail.com>
AuthorDate: Sun Oct 6 13:52:13 2024 +0100
fix fast api background process test (#42781)
---
tests/cli/commands/_common_cli_classes.py | 10 ++++++++++
tests/cli/commands/test_fastapi_api_command.py | 5 +----
tests/cli/commands/test_internal_api_command.py | 8 +-------
3 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/tests/cli/commands/_common_cli_classes.py b/tests/cli/commands/_common_cli_classes.py
index 77dfd41707f..37bbca0784a 100644
--- a/tests/cli/commands/_common_cli_classes.py
+++ b/tests/cli/commands/_common_cli_classes.py
@@ -146,3 +146,13 @@ class _CommonCLIGunicornTestClass:
console.print(proc.as_dict(attrs=["pid", "name", "cmdline"]))
pids.append(proc.pid)
return pids
+
+ def _terminate_multiple_process(self, pid_list):
+ process = []
+ for pid in pid_list:
+ proc = psutil.Process(pid)
+ proc.terminate()
+ process.append(proc)
+ gone, alive = psutil.wait_procs(process, timeout=120)
+ for p in alive:
+ p.kill()
diff --git a/tests/cli/commands/test_fastapi_api_command.py b/tests/cli/commands/test_fastapi_api_command.py
index 1c1af3342fa..2de4b729bfb 100644
--- a/tests/cli/commands/test_fastapi_api_command.py
+++ b/tests/cli/commands/test_fastapi_api_command.py
@@ -22,7 +22,6 @@ import sys
import time
from unittest import mock
-import psutil
import pytest
from rich.console import Console
@@ -89,9 +88,7 @@ class TestCliFastAPI(_CommonCLIGunicornTestClass):
"[magenta]Terminating monitor process and expect "
"fastapi-api and gunicorn processes to terminate as well"
)
- proc = psutil.Process(pid_monitor)
- proc.terminate()
- assert proc.wait(120) in (0, None)
+ self._terminate_multiple_process([pid_fastapi_api, pid_monitor])
self._check_processes(ignore_running=False)
console.print("[magenta]All fastapi-api and gunicorn processes are terminated.")
except Exception:
diff --git a/tests/cli/commands/test_internal_api_command.py b/tests/cli/commands/test_internal_api_command.py
index d821cc0246e..194f7874839 100644
--- a/tests/cli/commands/test_internal_api_command.py
+++ b/tests/cli/commands/test_internal_api_command.py
@@ -141,13 +141,7 @@ class TestCliInternalAPI(_CommonCLIGunicornTestClass):
"[magenta]Terminating monitor process and expect "
"internal-api and gunicorn processes to terminate as well"
)
- internal_api_proc = psutil.Process(pid_internal_api)
- internal_api_proc.terminate()
- proc = psutil.Process(pid_monitor)
- proc.terminate()
- gone, alive = psutil.wait_procs([internal_api_proc, proc], timeout=120)
- for p in alive:
- p.kill()
+ self._terminate_multiple_process([pid_internal_api, pid_monitor])
self._check_processes(ignore_running=False)
console.print("[magenta]All internal-api and gunicorn processes are terminated.")
except Exception: