From: Otto Moerbeek Date: Fri, 18 Nov 2022 09:38:48 +0000 (+0100) Subject: Use smart&fast killProcess from recursor regresssion test X-Git-Tag: dnsdist-1.8.0-rc1~229^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e4284d0540d852a771bbbb9b511914ee0a283b2f;p=thirdparty%2Fpdns.git Use smart&fast killProcess from recursor regresssion test --- diff --git a/regression-tests.dnsdist/dnsdisttests.py b/regression-tests.dnsdist/dnsdisttests.py index 253b84a7fb..069578a619 100644 --- a/regression-tests.dnsdist/dnsdisttests.py +++ b/regression-tests.dnsdist/dnsdisttests.py @@ -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):