]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Wait for dnsdist to exit in CheckConfig tests 3834/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 9 May 2016 14:13:14 +0000 (16:13 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 9 May 2016 14:13:14 +0000 (16:13 +0200)
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

index 71a7132bce4ea25d607ff3830ef304acebaacd72..eaed2bc84f4a83ffeaa431782f9381dc0858d5a2 100644 (file)
@@ -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)