You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2023/09/15 14:34:00 UTC

[airflow] branch main updated: Get rid of flakiness in CLI gunicorn tests (#34387)

This is an automated email from the ASF dual-hosted git repository.

potiuk 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 3854264a31 Get rid of flakiness in CLI gunicorn tests (#34387)
3854264a31 is described below

commit 3854264a31ba5c7718c51a034154f12483ad78d3
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Fri Sep 15 16:33:54 2023 +0200

    Get rid of flakiness in CLI gunicorn tests (#34387)
    
    The cli background tests had failed randomly from time to time
    with "NoSuchProcess" exception. For example in:
    https://github.com/apache/airflow/actions/runs/6194862351/job/16819105464
    
    The root cause of it was a race condition - when the process
    exited after we retrived the list of processes but before we attempted
    to kill it, creating of Process object failed with NoSuchProcess.
    
    This PR catches such exceptions individually and let the iteration
    process continue with killing other processes.
---
 tests/cli/commands/_common_cli_classes.py | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tests/cli/commands/_common_cli_classes.py b/tests/cli/commands/_common_cli_classes.py
index 946c029241..22299fe6a8 100644
--- a/tests/cli/commands/_common_cli_classes.py
+++ b/tests/cli/commands/_common_cli_classes.py
@@ -20,10 +20,11 @@ from __future__ import annotations
 import os
 import re
 import time
+from contextlib import suppress
 
 import psutil
 import pytest
-from psutil import Error
+from psutil import Error, NoSuchProcess
 from rich.console import Console
 
 from airflow.cli import cli_parser
@@ -55,16 +56,19 @@ class _ComonCLIGunicornTestClass:
         if airflow_internal_api_pids or gunicorn_pids:
             console.print("[blue]Some processes are still running")
             for pid in gunicorn_pids + airflow_internal_api_pids:
-                console.print(psutil.Process(pid).as_dict(attrs=["pid", "name", "cmdline"]))
+                with suppress(NoSuchProcess):
+                    console.print(psutil.Process(pid).as_dict(attrs=["pid", "name", "cmdline"]))
             console.print("[blue]Here list of processes ends")
             if airflow_internal_api_pids:
                 console.print(f"[yellow]Forcefully killing {self.main_process_regexp} processes")
                 for pid in airflow_internal_api_pids:
-                    psutil.Process(pid).kill()
+                    with suppress(NoSuchProcess):
+                        psutil.Process(pid).kill()
             if gunicorn_pids:
                 console.print("[yellow]Forcefully killing all gunicorn processes")
                 for pid in gunicorn_pids:
-                    psutil.Process(pid).kill()
+                    with suppress(NoSuchProcess):
+                        psutil.Process(pid).kill()
             if not ignore_running:
                 raise AssertionError(
                     "Background processes are running that prevent the test from passing successfully."