From 860c22f685ff19528d4420f9500e211ddd0afccd Mon Sep 17 00:00:00 2001 From: Tomas Krizek <tomas.krizek@nic.cz> Date: Fri, 4 Jan 2019 15:08:04 +0100 Subject: [PATCH] pytests/kresd: improve backoff when establishing initial kresd connection --- tests/pytests/kresd.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/pytests/kresd.py b/tests/pytests/kresd.py index aa0dcfac9..0963f1ef3 100644 --- a/tests/pytests/kresd.py +++ b/tests/pytests/kresd.py @@ -136,14 +136,22 @@ class Kresd(ContextDecorator): alive &= utils.try_ping_alive(self.ip6_tls_socket(), close=True, msgid=msgid + 3) return alive - def _wait_for_tcp_port(self, delay=0.1, max_attempts=50): + def _wait_for_tcp_port(self, max_delay=10, delay_step=0.2): family = socket.AF_INET if self.ip else socket.AF_INET6 - for _ in range(max_attempts): + i = 0 + end_time = time.time() + max_delay + + while time.time() < end_time: + i += 1 + + # use exponential backoff algorhitm to choose next delay + rand_delay = random.randrange(0, i) + time.sleep(rand_delay * delay_step) + try: sock, dest = self.stream_socket(family, timeout=5) sock.connect(dest) except ConnectionRefusedError: - time.sleep(delay) continue else: return utils.try_ping_alive(sock, close=True, msgid=10000) -- GitLab