Fix tests where broker suddenly disconnects client

This seems to be required just on more modern Python versions.
pull/1514/head
Roger A. Light 6 years ago
parent aceabcdef2
commit 28c11f4cce

@ -22,8 +22,10 @@ try:
sock.close() sock.close()
if len(data) == 0: if len(data) == 0:
rc = 0 rc = 0
except socket.error: except socket.error as e:
rc = 0 if e.errno == errno.ECONNRESET:
# Connection has been closed by peer, this is the expected behaviour
rc = 0
finally: finally:
broker.terminate() broker.terminate()
broker.wait() broker.wait()

@ -3,8 +3,6 @@
# 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
@ -17,10 +15,9 @@ 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: except socket.error as e:
if e.errno == errno.ECONNRESET: if e.errno == errno.ECONNRESET:
# Connection has been closed by peer (very quickly). # Connection has been closed by peer, this is the expected behaviour
# Fine, this is the expected behavior.
rc = 0 rc = 0
finally: finally:
broker.terminate() broker.terminate()

@ -51,6 +51,10 @@ try:
rc = 0 rc = 0
sock.close() 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: finally:
broker.terminate() broker.terminate()
broker.wait() broker.wait()

@ -47,6 +47,10 @@ try:
rc = 0 rc = 0
sock.close() 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: finally:
broker.terminate() broker.terminate()
broker.wait() broker.wait()

@ -50,6 +50,10 @@ try:
rc = 0 rc = 0
sock.close() 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: finally:
broker.terminate() broker.terminate()
broker.wait() broker.wait()

@ -53,6 +53,10 @@ try:
rc = 0 rc = 0
sock.close() 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: finally:
broker.terminate() broker.terminate()
broker.wait() broker.wait()

@ -50,6 +50,10 @@ try:
rc = 0 rc = 0
sock.close() 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: finally:
broker.terminate() broker.terminate()
broker.wait() broker.wait()

@ -3,8 +3,6 @@
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
@ -18,10 +16,9 @@ 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: except socket.error as e:
if e.errno == errno.ECONNRESET: if e.errno == errno.ECONNRESET:
# Connection has been closed by peer (very quickly). # Connection has been closed by peer, this is the expected behaviour
# Fine, this is the expected behavior.
rc = 0 rc = 0
finally: finally:
broker.terminate() broker.terminate()

@ -3,7 +3,6 @@
# Test whether a client can connect without an SSL certificate if one is required. # Test whether a client can connect without an SSL certificate if one is required.
from mosq_test_helper import * from mosq_test_helper import *
import errno
if sys.version < '2.7': if sys.version < '2.7':
print("WARNING: SSL not supported on Python 2.6") print("WARNING: SSL not supported on Python 2.6")

@ -15,3 +15,4 @@ import ssl
import struct import struct
import subprocess import subprocess
import time import time
import errno

Loading…
Cancel
Save