]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Use smart&fast killProcess from recursor regresssion test
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 18 Nov 2022 09:38:48 +0000 (10:38 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 18 Nov 2022 09:38:48 +0000 (10:38 +0100)
regression-tests.dnsdist/dnsdisttests.py

index 253b84a7fbdc39e49a1fe7780030d7c80989996d..069578a619477322cc7ca3e0b2a5e283e30121a2 100644 (file)
@@ -142,6 +142,29 @@ class DNSDistTest(AssertEqualDNSMessageMixin, unittest.TestCase):
         cls._sock.settimeout(2.0)
         cls._sock.connect(("127.0.0.1", cls._dnsDistPort))
 
+    @classmethod
+    def killProcess(cls, p):
+        # Don't try to kill it if it's already dead
+        if p.poll() is not None:
+            return
+        try:
+            p.terminate()
+            for count in range(10):
+                x = p.poll()
+                if x is not None:
+                    break
+                time.sleep(0.1)
+            if x is None:
+                print("kill...", p, file=sys.stderr)
+                p.kill()
+                p.wait()
+        except OSError as e:
+            # There is a race-condition with the poll() and
+            # kill() statements, when the process is dead on the
+            # kill(), this is fine
+            if e.errno != errno.ESRCH:
+                raise
+
     @classmethod
     def setUpClass(cls):
 
@@ -153,22 +176,7 @@ class DNSDistTest(AssertEqualDNSMessageMixin, unittest.TestCase):
 
     @classmethod
     def tearDownClass(cls):
-        cls._sock.close()
-        if 'DNSDIST_FAST_TESTS' in os.environ:
-            delay = 0.1
-        else:
-            delay = 1.0
-        if cls._dnsdist:
-            cls._dnsdist.terminate()
-            if cls._dnsdist.poll() is None:
-                time.sleep(delay)
-                if cls._dnsdist.poll() is None:
-                    cls._dnsdist.kill()
-                cls._dnsdist.wait()
-
-        # tell the background threads to stop, if any
-        for backgroundThread in cls._backgroundThreads:
-          cls._backgroundThreads[backgroundThread] = False
+        cls.killProcess(cls._dnsdist)
 
     @classmethod
     def _ResponderIncrementCounter(cls):