From 61b4aa90c13c6db11e622170585a05d78c9821ad Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 9 May 2016 16:13:14 +0200 Subject: [PATCH] dnsdist: Wait for dnsdist to exit in CheckConfig tests Otherwise we can't be sure that the exit code is the one we expected. Use `addACL()` instead of `newServer()` for the invalid parameter test, as `newServer()` is skipped in client mode, and `check-config` is run in this mode to prevent bind issues. --- regression-tests.dnsdist/test_CheckConfig.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/regression-tests.dnsdist/test_CheckConfig.py b/regression-tests.dnsdist/test_CheckConfig.py index 71a7132bce..eaed2bc84f 100644 --- a/regression-tests.dnsdist/test_CheckConfig.py +++ b/regression-tests.dnsdist/test_CheckConfig.py @@ -3,11 +3,11 @@ import unittest import os import subprocess import sys +import time class TestCheckConfig(unittest.TestCase): - @staticmethod - def tryDNSDist(configTemplate, shouldBeSuccessful=True): + def tryDNSDist(self, configTemplate, shouldBeSuccessful=True, delay=1): conffile = 'dnsdist_test.conf' with open(conffile, 'w') as conf: conf.write("-- Autogenerated by dnsdisttests.py\n") @@ -18,10 +18,14 @@ class TestCheckConfig(unittest.TestCase): with open(os.devnull, 'w') as fdDevNull: dnsdist = subprocess.Popen(dnsdistcmd, close_fds=True, stdout=fdDevNull) - if dnsdist.poll() is not None: - if dnsdist.returncode != 0 and not shouldBeSuccessful: - sys.exit(1) - sys.exit(0) + if dnsdist.poll() is None: + time.sleep(delay) + self.assertNotEqual(dnsdist.poll(), None) + + if shouldBeSuccessful: + self.assertEquals(dnsdist.returncode, 0) + else: + self.assertNotEqual(dnsdist.returncode, 0) def testWorkingConfig(self): """ @@ -70,7 +74,7 @@ class TestCheckConfig(unittest.TestCase): CheckConfig: Invalid parameter """ configTemplate = """ - newServer { address="127.0.0.355" } + addACL("127.0.0.355") """ self.tryDNSDist(configTemplate, False) -- 2.47.2