]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Ensure named always terminates in the shutdown test
authorTom Krizek <tkrizek@isc.org>
Thu, 6 Apr 2023 12:05:30 +0000 (14:05 +0200)
committerTom Krizek <tkrizek@isc.org>
Wed, 10 May 2023 11:32:55 +0000 (13:32 +0200)
Previously, if an exception would happen inside the `with` block, the
error handler would wait indefinitely for the process to end. That would
never happen, since the termination signal was never sent to named and
the test would get stuck.

Using the try-finally block ensures that the named process is always
killed and any exception or errors will be handled gracefully.

(cherry picked from commit 836e6ed284b9f62c49b06db944db83d508d4a054)

bin/tests/system/shutdown/tests_shutdown.py

index 8e31f8fc460e46eeb04790f3256c99c019508568..b6083b77a25b6ffebeea19d6da88c3782869c65b 100755 (executable)
@@ -192,15 +192,18 @@ def test_named_shutdown(named_port, control_port):
     for kill_method in ("rndc", "sigterm"):
         named_cmdline = [named, "-c", cfg_file, "-f"]
         with subprocess.Popen(named_cmdline, cwd=cfg_dir) as named_proc:
-            assert named_proc.poll() is None, "named isn't running"
-            assert wait_for_named_loaded(resolver)
-            do_work(
-                named_proc,
-                resolver,
-                rndc_cmd,
-                kill_method,
-                n_workers=12,
-                n_queries=16,
-            )
-            assert wait_for_proc_termination(named_proc)
-            assert named_proc.returncode == 0, "named crashed"
+            try:
+                assert named_proc.poll() is None, "named isn't running"
+                assert wait_for_named_loaded(resolver)
+                do_work(
+                    named_proc,
+                    resolver,
+                    rndc_cmd,
+                    kill_method,
+                    n_workers=12,
+                    n_queries=16,
+                )
+                assert wait_for_proc_termination(named_proc)
+                assert named_proc.returncode == 0, "named crashed"
+            finally:  # Ensure named is terminated in case of an exception
+                named_proc.kill()