From 28c11f4ccee25c317972514e64e66cca101ee262 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 6 Nov 2019 14:07:07 +0000 Subject: [PATCH] Fix tests where broker suddenly disconnects client This seems to be required just on more modern Python versions. --- test/broker/01-connect-bad-packet.py | 6 ++++-- test/broker/01-connect-invalid-reserved.py | 7 ++----- test/broker/02-subpub-qos1-bad-pubcomp.py | 4 ++++ test/broker/02-subpub-qos1-bad-pubrec.py | 4 ++++ test/broker/02-subpub-qos2-bad-puback-1.py | 4 ++++ test/broker/02-subpub-qos2-bad-puback-2.py | 4 ++++ test/broker/02-subpub-qos2-bad-pubcomp.py | 4 ++++ test/broker/07-will-null-topic.py | 7 ++----- test/broker/08-ssl-connect-cert-auth-without.py | 1 - test/broker/mosq_test_helper.py | 1 + 10 files changed, 29 insertions(+), 13 deletions(-) diff --git a/test/broker/01-connect-bad-packet.py b/test/broker/01-connect-bad-packet.py index 87300ad8..50e4ee2f 100755 --- a/test/broker/01-connect-bad-packet.py +++ b/test/broker/01-connect-bad-packet.py @@ -22,8 +22,10 @@ try: sock.close() if len(data) == 0: rc = 0 -except socket.error: - rc = 0 +except socket.error as e: + if e.errno == errno.ECONNRESET: + # Connection has been closed by peer, this is the expected behaviour + rc = 0 finally: broker.terminate() broker.wait() diff --git a/test/broker/01-connect-invalid-reserved.py b/test/broker/01-connect-invalid-reserved.py index befbb2d8..1aa35131 100755 --- a/test/broker/01-connect-invalid-reserved.py +++ b/test/broker/01-connect-invalid-reserved.py @@ -3,8 +3,6 @@ # 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 @@ -17,10 +15,9 @@ try: sock = mosq_test.do_client_connect(connect_packet, b"", port=port) sock.close() rc = 0 -except SocketError as e: +except socket.error as e: if e.errno == errno.ECONNRESET: - # Connection has been closed by peer (very quickly). - # Fine, this is the expected behavior. + # Connection has been closed by peer, this is the expected behaviour rc = 0 finally: broker.terminate() diff --git a/test/broker/02-subpub-qos1-bad-pubcomp.py b/test/broker/02-subpub-qos1-bad-pubcomp.py index 30000da1..93dde6fa 100755 --- a/test/broker/02-subpub-qos1-bad-pubcomp.py +++ b/test/broker/02-subpub-qos1-bad-pubcomp.py @@ -51,6 +51,10 @@ try: rc = 0 sock.close() +except socket.error as e: + if e.errno == errno.ECONNRESET: + # Connection has been closed by peer, this is the expected behaviour + rc = 0 finally: broker.terminate() broker.wait() diff --git a/test/broker/02-subpub-qos1-bad-pubrec.py b/test/broker/02-subpub-qos1-bad-pubrec.py index f7d416e4..5421beeb 100755 --- a/test/broker/02-subpub-qos1-bad-pubrec.py +++ b/test/broker/02-subpub-qos1-bad-pubrec.py @@ -47,6 +47,10 @@ try: rc = 0 sock.close() +except socket.error as e: + if e.errno == errno.ECONNRESET: + # Connection has been closed by peer, this is the expected behaviour + rc = 0 finally: broker.terminate() broker.wait() diff --git a/test/broker/02-subpub-qos2-bad-puback-1.py b/test/broker/02-subpub-qos2-bad-puback-1.py index dd4bb7fd..5a983103 100755 --- a/test/broker/02-subpub-qos2-bad-puback-1.py +++ b/test/broker/02-subpub-qos2-bad-puback-1.py @@ -50,6 +50,10 @@ try: rc = 0 sock.close() +except socket.error as e: + if e.errno == errno.ECONNRESET: + # Connection has been closed by peer, this is the expected behaviour + rc = 0 finally: broker.terminate() broker.wait() diff --git a/test/broker/02-subpub-qos2-bad-puback-2.py b/test/broker/02-subpub-qos2-bad-puback-2.py index 41bcc77b..3813abc9 100755 --- a/test/broker/02-subpub-qos2-bad-puback-2.py +++ b/test/broker/02-subpub-qos2-bad-puback-2.py @@ -53,6 +53,10 @@ try: rc = 0 sock.close() +except socket.error as e: + if e.errno == errno.ECONNRESET: + # Connection has been closed by peer, this is the expected behaviour + rc = 0 finally: broker.terminate() broker.wait() diff --git a/test/broker/02-subpub-qos2-bad-pubcomp.py b/test/broker/02-subpub-qos2-bad-pubcomp.py index 0b841be8..fa909aa7 100755 --- a/test/broker/02-subpub-qos2-bad-pubcomp.py +++ b/test/broker/02-subpub-qos2-bad-pubcomp.py @@ -50,6 +50,10 @@ try: rc = 0 sock.close() +except socket.error as e: + if e.errno == errno.ECONNRESET: + # Connection has been closed by peer, this is the expected behaviour + rc = 0 finally: broker.terminate() broker.wait() diff --git a/test/broker/07-will-null-topic.py b/test/broker/07-will-null-topic.py index 0172b48b..122a1f5f 100755 --- a/test/broker/07-will-null-topic.py +++ b/test/broker/07-will-null-topic.py @@ -3,8 +3,6 @@ import struct from mosq_test_helper import * -from socket import error as SocketError -import errno rc = 1 keepalive = 60 @@ -18,10 +16,9 @@ try: sock = mosq_test.do_client_connect(connect_packet, b"", timeout=30, port=port) rc = 0 sock.close() -except SocketError as e: +except socket.error as e: if e.errno == errno.ECONNRESET: - # Connection has been closed by peer (very quickly). - # Fine, this is the expected behavior. + # Connection has been closed by peer, this is the expected behaviour rc = 0 finally: broker.terminate() diff --git a/test/broker/08-ssl-connect-cert-auth-without.py b/test/broker/08-ssl-connect-cert-auth-without.py index c28ab5d9..cf8cb692 100755 --- a/test/broker/08-ssl-connect-cert-auth-without.py +++ b/test/broker/08-ssl-connect-cert-auth-without.py @@ -3,7 +3,6 @@ # Test whether a client can connect without an SSL certificate if one is required. from mosq_test_helper import * -import errno if sys.version < '2.7': print("WARNING: SSL not supported on Python 2.6") diff --git a/test/broker/mosq_test_helper.py b/test/broker/mosq_test_helper.py index 73548396..52c0ed51 100644 --- a/test/broker/mosq_test_helper.py +++ b/test/broker/mosq_test_helper.py @@ -15,3 +15,4 @@ import ssl import struct import subprocess import time +import errno