pytests: fix utils.ping_alive

parent 6465b672
......@@ -67,7 +67,7 @@ def test_conn_flood(tmpdir, sock_func_name):
print("Start sending data")
for i in range(MAX_ITERATIONS):
for s in sockets:
assert utils.ping_alive(s)
utils.ping_alive(s)
print("Iteration {} done...".format(i))
print("Close connections")
......@@ -77,6 +77,6 @@ def test_conn_flood(tmpdir, sock_func_name):
# check in kresd is alive
print("Check upstream is still alive")
sock = make_sock()
assert utils.ping_alive(sock)
utils.ping_alive(sock)
print("OK!")
......@@ -72,7 +72,7 @@ class Kresd(ContextDecorator):
# issue special msgid to mark start of test log
sock = self.ip_tcp_socket() if self.ip else self.ip6_tcp_socket()
utils.ping_alive(sock, close=True, msgid=KRESD_STARTUP_MSGID)
assert utils.try_ping_alive(sock, close=True, msgid=KRESD_STARTUP_MSGID)
# sanity check - kresd didn't crash
self.process.poll()
......@@ -105,11 +105,11 @@ class Kresd(ContextDecorator):
def all_ports_alive(self, msgid=10001):
alive = True
if self.ip:
alive &= utils.ping_alive(self.ip_tls_socket(), close=True, msgid=msgid)
alive &= utils.ping_alive(self.ip_tcp_socket(), close=True, msgid=msgid + 1)
alive &= utils.try_ping_alive(self.ip_tls_socket(), close=True, msgid=msgid)
alive &= utils.try_ping_alive(self.ip_tcp_socket(), close=True, msgid=msgid + 1)
if self.ip6:
alive &= utils.ping_alive(self.ip6_tls_socket(), close=True, msgid=msgid + 2)
alive &= utils.ping_alive(self.ip6_tcp_socket(), close=True, msgid=msgid + 3)
alive &= utils.try_ping_alive(self.ip6_tls_socket(), close=True, msgid=msgid + 2)
alive &= utils.try_ping_alive(self.ip6_tcp_socket(), close=True, msgid=msgid + 3)
return alive
def _wait_for_tcp_port(self, delay=0.1, max_attempts=20):
......@@ -122,7 +122,7 @@ class Kresd(ContextDecorator):
time.sleep(delay)
continue
else:
return utils.ping_alive(sock, close=True, msgid=10000)
return utils.try_ping_alive(sock, close=True, msgid=10000)
finally:
sock.close()
raise RuntimeError("Kresd didn't start in time")
......
......@@ -77,13 +77,22 @@ def get_prefixed_garbage(length):
return prepare_buffer(data)
def ping_alive(sock, msgid=None, close=False):
def try_ping_alive(sock, msgid=None, close=False):
try:
ping_alive(sock, msgid)
except AssertionError:
return False
finally:
if close:
sock.close()
return True
def ping_alive(sock, msgid=None):
buff, msgid = get_msgbuff(msgid=msgid)
sock.sendall(buff)
answer = receive_parse_answer(sock)
if close:
sock.close()
return answer.id == msgid
assert answer.id == msgid
@contextmanager
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment