Skip to content

Commit

Permalink
add test for bridge_fatal_sub_errors
Browse files Browse the repository at this point in the history
Signed-off-by: Abilio Marques <[email protected]>
  • Loading branch information
abiliojr committed Jul 7, 2024
1 parent 91fc7ad commit 88a6adf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python3

# Does a bridge disconnect on subscription errors?
# Does a bridge with bridge_fatal_sub_errors enabled
# disconnect on subscription errors? Does it remain connected otherwise?

from mosq_test_helper import *

def write_config(filename, port1, port2):
def write_config(filename, port1, port2, fatal_sub_errors):
with open(filename, 'w') as f:
f.write("listener %d\n" % (port2))
f.write("allow_anonymous true\n")
Expand All @@ -15,6 +16,7 @@ def write_config(filename, port1, port2):
f.write("notifications false\n")
f.write("restart_timeout 5\n")
f.write("cleansession true\n")
f.write("bridge_fatal_sub_errors %s\n" % str(fatal_sub_errors).lower())

def is_connected(sock):
try:
Expand All @@ -23,10 +25,10 @@ def is_connected(sock):
except TimeoutError as e:
return True

def do_test():
def do_test(fatal_sub_errors):
(port1, port2) = mosq_test.get_port(2)
conf_file = os.path.basename(__file__).replace('.py', '.conf')
write_config(conf_file, port1, port2)
write_config(conf_file, port1, port2, fatal_sub_errors)

rc = 1
client_id = socket.gethostname()+".bridge_sample"
Expand Down Expand Up @@ -59,8 +61,8 @@ def do_test():

time.sleep(0.25) # give the broker some time to react

# should be disconnected by now
rc = bool(is_connected(bridge))
# if (connected and not fatal) or (disconnected and fatal): success, else: failure
rc = 0 if is_connected(bridge) != fatal_sub_errors else 1
except mosq_test.TestError:
pass
finally:
Expand All @@ -80,6 +82,7 @@ def do_test():
print(stde.decode('utf-8'))
exit(rc)

do_test()
do_test(True)
do_test(False)

exit(0)
1 change: 1 addition & 0 deletions test/broker/16-config-huge.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def write_config(filename, ports, per_listener_settings, plugver, acl_file):
f.write("bridge_max_packet_size 10000\n")
f.write("bridge_max_topic_alias 1000\n")
f.write("bridge_outgoing_retain false\n")
f.write("bridge_fatal_sub_errors false\n")
f.write("bridge_protocol_version mqttv50\n")
#f.write("bridge_psk\n")
f.write("bridge_receive_maximum 100\n")
Expand Down
1 change: 1 addition & 0 deletions test/broker/16-config-parse-errors-without-tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
do_test_broker_failure(conf_file, ["bridge_max_packet_size 1000"], port, 3, "Error: The 'bridge_max_packet_size' option requires a bridge to be defined first.") # Missing bridge config
do_test_broker_failure(conf_file, ["bridge_max_topic_alias 1000"], port, 3, "Error: The 'bridge_max_topic_alias' option requires a bridge to be defined first.") # Missing bridge config
do_test_broker_failure(conf_file, ["bridge_outgoing_retain false"], port, 3, "Error: The 'bridge_outgoing_retain' option requires a bridge to be defined first.") # Missing bridge config
do_test_broker_failure(conf_file, ["bridge_fatal_sub_errors false"], 3, "Error: The 'bridge_fatal_sub_errors' option requires a bridge to be defined first.") # Missing bridge config
do_test_broker_failure(conf_file, ["bridge_protocol_version string"], port, 3, "Error: The 'bridge_protocol_version' option requires a bridge to be defined first.") # Missing bridge config
do_test_broker_failure(conf_file, ["bridge_receive_maximum 10"], port, 3, "Error: The 'bridge_receive_maximum' option requires a bridge to be defined first.") # Missing bridge config
do_test_broker_failure(conf_file, ["bridge_reload_type string"], port, 3, "Error: The 'bridge_reload_type' option requires a bridge to be defined first.") # Missing bridge config
Expand Down
1 change: 1 addition & 0 deletions test/broker/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
(2, './06-bridge-reconnect-local-out.py'),
(2, './06-bridge-remote-shutdown.py'),
(2, './06-bridge-config-reload.py'),
(2, './06-bridge-fatal-sub-errors.py'),

(1, './07-will-control.py'),
(1, './07-will-delay-invalid-573191.py'),
Expand Down

0 comments on commit 88a6adf

Please sign in to comment.