From: Otto Moerbeek Date: Mon, 10 Feb 2025 13:21:01 +0000 (+0100) Subject: Make dnstap test handle EOF and wait on process to exit. X-Git-Tag: dnsdist-2.0.0-alpha1~96^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b138c385755677aa27c289bea68331baf3de3f1;p=thirdparty%2Fpdns.git Make dnstap test handle EOF and wait on process to exit. The wait is essential if you have multiple tests classes in a test file. --- diff --git a/regression-tests.recursor-dnssec/recursortests.py b/regression-tests.recursor-dnssec/recursortests.py index 284b942552..6ca75e2dc3 100644 --- a/regression-tests.recursor-dnssec/recursortests.py +++ b/regression-tests.recursor-dnssec/recursortests.py @@ -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)) diff --git a/regression-tests.recursor-dnssec/runtests b/regression-tests.recursor-dnssec/runtests index 3543dd2b79..0553e07474 100755 --- a/regression-tests.recursor-dnssec/runtests +++ b/regression-tests.recursor-dnssec/runtests @@ -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 diff --git a/regression-tests.recursor-dnssec/test_Flags.py b/regression-tests.recursor-dnssec/test_Flags.py index 702d44de1d..da6d46eb5d 100644 --- a/regression-tests.recursor-dnssec/test_Flags.py +++ b/regression-tests.recursor-dnssec/test_Flags.py @@ -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) diff --git a/regression-tests.recursor-dnssec/test_RecDnstap.py b/regression-tests.recursor-dnssec/test_RecDnstap.py index 025b32c17a..c5dd367eda 100644 --- a/regression-tests.recursor-dnssec/test_RecDnstap.py +++ b/regression-tests.recursor-dnssec/test_RecDnstap.py @@ -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: