]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Make dnstap test handle EOF and wait on process to exit.
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 10 Feb 2025 13:21:01 +0000 (14:21 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 10 Feb 2025 13:21:01 +0000 (14:21 +0100)
The wait is essential if you have multiple tests classes in a test file.

regression-tests.recursor-dnssec/recursortests.py
regression-tests.recursor-dnssec/runtests
regression-tests.recursor-dnssec/test_Flags.py
regression-tests.recursor-dnssec/test_RecDnstap.py

index 284b9425529143bb4a6577afff26c7283186b8f2..6ca75e2dc383828d6572cc8ef14d7137cc29e79b 100644 (file)
@@ -765,7 +765,7 @@ distributor-threads={threads}""".format(confdir=confdir,
     def killProcess(cls, p):
         # Don't try to kill it if it's already dead
         if p.poll() is not None:
-            return
+            return p
         try:
             p.terminate()
             for count in range(100): # tsan can be slow
@@ -791,8 +791,28 @@ distributor-threads={threads}""".format(confdir=confdir,
             cls.killProcess(auth);
 
     @classmethod
-    def tearDownRecursor(cls):
-        p = cls.killProcess(cls._recursor)
+    def tearDownRecursor(cls, subdir=None):
+        # We now kill the recursor in a friendly way, as systemd is doing the same.
+        if subdir is None:
+            confdir = os.path.join('configs', cls._confdir)
+        else:
+            confdir = os.path.join('configs', cls._confdir, subdir)
+        rec_controlCmd = [os.environ['RECCONTROL'],
+                          '--config-dir=%s' % confdir,
+                          '--timeout=20',
+                          'quit-nicely']
+        try:
+            subprocess.check_output(rec_controlCmd, stderr=subprocess.STDOUT)
+        except subprocess.CalledProcessError as e:
+            raise AssertionError('%s failed (%d): %s' % (rec_controlCmd, e.returncode, e.output))
+        # Wait for it, as the process really should have exited
+        p = cls._recursor
+        for count in range(100): # tsan can be slow
+            if p.poll() is not None:
+                break;
+            time.sleep(0.1)
+        if p.poll() is None:
+            raise AssertionError('Process did not exit on request within 10s')
         if p.returncode not in (0, -15):
             raise AssertionError('Process exited with return code %d' % (p.returncode))
 
index 3543dd2b79c52b1d1548b64e77440adcaeda4804..0553e0747407e1801e82542bd8234585f7f5928c 100755 (executable)
@@ -3,6 +3,9 @@
 if pgrep pdns_server; then
     echo 'There are (stray?) pdns_servers running that might interfere with these tests!'
 fi
+if pgrep pdns_recursor; then
+    echo 'There are (stray?) pdns_recursors running that might interfere with these tests!'
+fi
 
 export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
 
index 702d44de1d970bf46edc2db0c9cf5c61291a3409..da6d46eb5dbb9389e55fb0d9eb97bdd4b6305401 100644 (file)
@@ -72,9 +72,9 @@ class FlagsTest(RecursorTest):
     @classmethod
     def tearDownClass(cls):
         cls.tearDownAuth()
-        for _, recursor in cls._recursors.items():
+        for subdir, recursor in cls._recursors.items():
             cls._recursor = recursor
-            cls.tearDownRecursor()
+            cls.tearDownRecursor(subdir)
 
     def getQueryForSecure(self, flags='', ednsflags=''):
         return self.createQuery('ns1.example.', 'A', flags, ednsflags)
index 025b32c17a8f8a8e0d62cb6e23f7310687f4c3b8..c5dd367eda7aead969a19c67bc32daf3708b1bde 100644 (file)
@@ -191,10 +191,9 @@ class TestRecursorDNSTap(RecursorTest):
                 if e.errno in (errno.EBADF, errno.EPIPE):
                     break
                 sys.stderr.write("Unexpected socket error %s\n" % str(e))
-                sys.exit(1)
-            except exception as e:
+            except Exception as e:
                 sys.stderr.write("Unexpected socket error %s\n" % str(e))
-                sys.exit(1)
+                break
         conn.close()
 
     @classmethod
@@ -208,8 +207,7 @@ class TestRecursorDNSTap(RecursorTest):
             sock.bind(param.path)
             sock.listen(100)
         except socket.error as e:
-            sys.stderr.write("Error binding/listening in the framestream listener: %s\n" % str(e))
-            sys.exit(1)
+            raise Exception("Error binding/listening in the framestream listener: %s\n" % str(e))
         DNSTapListeners.append(sock)
         while True:
             try: