]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Split shutdown test into separate test cases
authorTom Krizek <tkrizek@isc.org>
Mon, 26 Jun 2023 13:18:45 +0000 (15:18 +0200)
committerTom Krizek <tkrizek@isc.org>
Tue, 4 Jul 2023 10:58:14 +0000 (12:58 +0200)
The shutdown test attempts to shut down the server using two different
methods - rndc and sigterm. Use pytest.mark.parametrize to run these as
separate test cases for easier identification of failures.

bin/tests/system/shutdown/tests_shutdown.py

index 499dca323a8619db58087db8f160d97236146012..108c44cbb9507e87f36a51bdee5245b9b42a631d 100755 (executable)
@@ -156,7 +156,15 @@ def wait_for_proc_termination(proc, max_timeout=10):
     return False
 
 
-def test_named_shutdown(named_port, control_port):
+# We test named shutting down using two methods:
+# Method 1: using rndc ctop
+# Method 2: killing with SIGTERM
+# In both methods named should exit gracefully.
+@pytest.mark.parametrize("kill_method", [
+    "rndc",
+    "sigtem"
+])
+def test_named_shutdown(named_port, control_port, kill_method):
     # pylint: disable-msg=too-many-locals
     cfg_dir = os.path.join(os.getcwd(), "resolver")
     assert os.path.isdir(cfg_dir)
@@ -182,25 +190,20 @@ def test_named_shutdown(named_port, control_port):
     resolver.nameservers = ["10.53.0.3"]
     resolver.port = named_port
 
-    # We test named shutting down using two methods:
-    # Method 1: using rndc ctop
-    # Method 2: killing with SIGTERM
-    # In both methods named should exit gracefully.
-    for kill_method in ("rndc", "sigterm"):
-        named_cmdline = [named, "-c", cfg_file, "-f"]
-        with subprocess.Popen(named_cmdline, cwd=cfg_dir) as named_proc:
-            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()
+    named_cmdline = [named, "-c", cfg_file, "-f"]
+    with subprocess.Popen(named_cmdline, cwd=cfg_dir) as named_proc:
+        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()