Merge pull request #1487 from grom-42/fix-send-pkt

Fix test on invalid null will topic value in connect packet

Fix test on invalid reserved bit value in connect packet

Add send of pubcomp in 02-subpub-qos2 script. To keep the broker session working while launching several tests on the same broker, the last packet of this transaction must be sent.

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.
This commit is contained in:
Roger Light 2019-11-06 09:49:15 +00:00 committed by GitHub
commit 25f458de74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 2 deletions

View File

@ -3,6 +3,8 @@
# Test whether a CONNECT with reserved set to 1 results in a disconnect. MQTT-3.1.2-3 # Test whether a CONNECT with reserved set to 1 results in a disconnect. MQTT-3.1.2-3
from mosq_test_helper import * from mosq_test_helper import *
from socket import error as SocketError
import errno
rc = 1 rc = 1
keepalive = 10 keepalive = 10
@ -15,7 +17,11 @@ try:
sock = mosq_test.do_client_connect(connect_packet, b"", port=port) sock = mosq_test.do_client_connect(connect_packet, b"", port=port)
sock.close() sock.close()
rc = 0 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: finally:
broker.terminate() broker.terminate()
broker.wait() broker.wait()

View File

@ -38,6 +38,7 @@ try:
if mosq_test.expect_packet(sock, "publish2", publish_packet2): if mosq_test.expect_packet(sock, "publish2", publish_packet2):
mosq_test.do_send_receive(sock, pubrec_packet2, pubrel_packet2, "pubrel2") mosq_test.do_send_receive(sock, pubrec_packet2, pubrel_packet2, "pubrel2")
sock.send(pubcomp_packet2)
# Broker side of flow complete so can quit here. # Broker side of flow complete so can quit here.
rc = 0 rc = 0

View File

@ -3,6 +3,8 @@
import struct import struct
from mosq_test_helper import * from mosq_test_helper import *
from socket import error as SocketError
import errno
rc = 1 rc = 1
keepalive = 60 keepalive = 60
@ -16,6 +18,11 @@ try:
sock = mosq_test.do_client_connect(connect_packet, b"", timeout=30, port=port) sock = mosq_test.do_client_connect(connect_packet, b"", timeout=30, port=port)
rc = 0 rc = 0
sock.close() 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: finally:
broker.terminate() broker.terminate()
broker.wait() broker.wait()

View File

@ -106,7 +106,13 @@ def packet_matches(name, recvd, expected):
def do_send_receive(sock, send_packet, receive_packet, error_string="send receive error"): 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): if expect_packet(sock, error_string, receive_packet):
return sock return sock