Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridge subscription failure will cause a disconnect #2935

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
add test for bridge_fatal_sub_errors
Signed-off-by: Abilio Marques <[email protected]>
  • Loading branch information
abiliojr committed Oct 27, 2023
commit fd9ab88f3cd02c5df7b45999f0a1405a11233b87
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 @@ -41,6 +41,7 @@
do_test_broker_failure(conf_file, ["bridge_max_packet_size 1000"], 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"], 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"], 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"], 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"], 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"], 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