diff --git a/test/broker/01-connect-invalid-reserved.py b/test/broker/01-connect-invalid-reserved.py index 10f56c61..befbb2d8 100755 --- a/test/broker/01-connect-invalid-reserved.py +++ b/test/broker/01-connect-invalid-reserved.py @@ -3,6 +3,8 @@ # Test whether a CONNECT with reserved set to 1 results in a disconnect. MQTT-3.1.2-3 from mosq_test_helper import * +from socket import error as SocketError +import errno rc = 1 keepalive = 10 @@ -15,7 +17,11 @@ try: sock = mosq_test.do_client_connect(connect_packet, b"", port=port) sock.close() rc = 0 - +except SocketError as e: + if e.errno == errno.ECONNRESET: + # Connection has been closed by peer (very quickly). + # Fine, this is the expected behavior. + rc = 0 finally: broker.terminate() broker.wait() diff --git a/test/broker/02-subpub-qos2.py b/test/broker/02-subpub-qos2.py index 260e2eb9..1600a861 100755 --- a/test/broker/02-subpub-qos2.py +++ b/test/broker/02-subpub-qos2.py @@ -38,6 +38,7 @@ try: if mosq_test.expect_packet(sock, "publish2", publish_packet2): mosq_test.do_send_receive(sock, pubrec_packet2, pubrel_packet2, "pubrel2") + sock.send(pubcomp_packet2) # Broker side of flow complete so can quit here. rc = 0 diff --git a/test/broker/07-will-null-topic.py b/test/broker/07-will-null-topic.py index b6007541..0172b48b 100755 --- a/test/broker/07-will-null-topic.py +++ b/test/broker/07-will-null-topic.py @@ -3,6 +3,8 @@ import struct from mosq_test_helper import * +from socket import error as SocketError +import errno rc = 1 keepalive = 60 @@ -16,6 +18,11 @@ try: sock = mosq_test.do_client_connect(connect_packet, b"", timeout=30, port=port) rc = 0 sock.close() +except SocketError as e: + if e.errno == errno.ECONNRESET: + # Connection has been closed by peer (very quickly). + # Fine, this is the expected behavior. + rc = 0 finally: broker.terminate() broker.wait() 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