From: Tomas Krizek Date: Mon, 19 Nov 2018 14:58:22 +0000 (+0100) Subject: pytests: add predictable msgids to setup/teardown pings X-Git-Tag: v3.2.0~18^2~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07e36b63d0449a3dce86256183cf6b3f7df0ebea;p=thirdparty%2Fknot-resolver.git pytests: add predictable msgids to setup/teardown pings --- diff --git a/tests/pytests/kresd.py b/tests/pytests/kresd.py index 270358fc7..d91e0ed01 100644 --- a/tests/pytests/kresd.py +++ b/tests/pytests/kresd.py @@ -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") diff --git a/tests/pytests/utils.py b/tests/pytests/utils.py index a809d78d4..e3ccb2e78 100644 --- a/tests/pytests/utils.py +++ b/tests/pytests/utils.py @@ -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