]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
pytests: add predictable msgids to setup/teardown pings
authorTomas Krizek <tomas.krizek@nic.cz>
Mon, 19 Nov 2018 14:58:22 +0000 (15:58 +0100)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 4 Dec 2018 16:13:42 +0000 (17:13 +0100)
tests/pytests/kresd.py
tests/pytests/utils.py

index 270358fc77162269dd9acc8e7121cac5d6de323b..d91e0ed0158040dba8e42cc5cc0bf483c254d708 100644 (file)
@@ -66,7 +66,7 @@ class Kresd(ContextDecorator):
 
         try:
             self._wait_for_tcp_port()  # wait for ports to be up and responding
-            if not self.all_ports_alive():
+            if not self.all_ports_alive(msgid=10001):
                 raise RuntimeError("Kresd not listening on all ports")
             self.process.poll()
             if self.process.returncode is not None:
@@ -87,7 +87,7 @@ class Kresd(ContextDecorator):
 
     def __exit__(self, exc_type, exc_value, traceback):
         try:
-            if not self.all_ports_alive():
+            if not self.all_ports_alive(msgid=1005):
                 raise RuntimeError("Kresd crashed")
         finally:
             for sock in self.sockets:
@@ -95,14 +95,14 @@ class Kresd(ContextDecorator):
             self.process.terminate()
             self.logfile.close()
 
-    def all_ports_alive(self):
+    def all_ports_alive(self, msgid=10001):
         alive = True
         if self.ip:
-            alive &= utils.ping_alive(self.ip_tcp_socket())
-            alive &= utils.ping_alive(self.ip_tls_socket())
+            alive &= utils.ping_alive(self.ip_tcp_socket(), msgid=msgid)
+            alive &= utils.ping_alive(self.ip_tls_socket(), msgid=msgid + 1)
         if self.ip6:
-            alive &= utils.ping_alive(self.ip6_tcp_socket())
-            alive &= utils.ping_alive(self.ip6_tls_socket())
+            alive &= utils.ping_alive(self.ip6_tcp_socket(), msgid=msgid + 2)
+            alive &= utils.ping_alive(self.ip6_tls_socket(), msgid=msgid + 3)
         return alive
 
     def _wait_for_tcp_port(self, delay=0.1, max_attempts=20):
@@ -115,7 +115,7 @@ class Kresd(ContextDecorator):
                 time.sleep(delay)
                 continue
             else:
-                return utils.ping_alive(sock)
+                return utils.ping_alive(sock, msgid=10000)
             finally:
                 sock.close()
         raise RuntimeError("Kresd didn't start in time")
index a809d78d45e0e8d1aec493ad09fe59f8359cd630..e3ccb2e78d3b5e3dc9df45e458ebbef2011571cb 100644 (file)
@@ -77,8 +77,8 @@ def get_prefixed_garbage(length):
     return prepare_buffer(data)
 
 
-def ping_alive(sock):
-    buff, msgid = get_msgbuff()
+def ping_alive(sock, msgid=None):
+    buff, msgid = get_msgbuff(msgid=msgid)
     sock.sendall(buff)
     answer = receive_parse_answer(sock)
     return answer.id == msgid