From d76e5fd199b3b3a06e549104efeffde2ceae4aae Mon Sep 17 00:00:00 2001 From: Jerome Malinge Date: Wed, 30 Oct 2019 16:07:20 +0100 Subject: [PATCH] Fix way of sending packets in compliance tests According to the documentation of python 3 socket::send method (https://docs.python.org/3/library/socket.html#socket.socket.send), the call to send must be retry until all data is sent while sending packet with a "large" amount of data. Signed-off-by: Jerome Malinge --- test/mosq_test.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/mosq_test.py b/test/mosq_test.py index 1669f566..c4b9808d 100644 --- a/test/mosq_test.py +++ b/test/mosq_test.py @@ -106,7 +106,13 @@ def packet_matches(name, recvd, expected): def do_send_receive(sock, send_packet, receive_packet, error_string="send receive error"): - sock.send(send_packet) + size = len(send_packet) + total_sent = 0 + while total_sent < size: + sent = sock.send(send_packet[total_sent:]) + if sent == 0: + raise RuntimeError("socket connection broken") + total_sent += sent if expect_packet(sock, error_string, receive_packet): return sock