mik-laj commented on a change in pull request #6579: [AIRFLOW-5926] Fix 
race-condition in TestCliWebServer
URL: https://github.com/apache/airflow/pull/6579#discussion_r346068956
 
 

 ##########
 File path: tests/cli/test_cli.py
 ##########
 @@ -761,6 +761,31 @@ class TestCliWebServer(unittest.TestCase):
     def setUpClass(cls):
         cls.parser = cli.CLIFactory.get_parser()
 
+    def setUp(self) -> None:
+        self._check_processes()
+        self._clean_pidfiles()
+
+    def _check_processes(self):
+        try:
+            # Confirm that webserver hasn't been launched.
+            # pgrep returns exit status 1 if no process matched.
+            self.assertEqual(1, subprocess.Popen(["pgrep", "-f", "-c", 
"airflow webserver"]).wait())
+            self.assertEqual(1, subprocess.Popen(["pgrep", "-c", 
"gunicorn"]).wait())
+        except:  # noqa: E722
+            subprocess.Popen(["ps", "-ax"]).wait()
+            raise
+
+    def tearDown(self) -> None:
+        self._check_processes()
+
+    def _clean_pidfiles(self):
+        pidfile_webserver = cli.setup_locations("webserver")[0]
+        pidfile_monitor = cli.setup_locations("webserver-monitor")[0]
 
 Review comment:
   This can cause another race condition.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to