From 81175b442f4e4e3c9c8aa807b92047f73647458e Mon Sep 17 00:00:00 2001 From: pennae Date: Sun, 24 Oct 2021 19:11:45 +0200 Subject: [PATCH] nixos/mosquitto: refactor test a little --- nixos/tests/mosquitto.nix | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/nixos/tests/mosquitto.nix b/nixos/tests/mosquitto.nix index eb47e97ba04b..bcca5372eaef 100644 --- a/nixos/tests/mosquitto.nix +++ b/nixos/tests/mosquitto.nix @@ -136,9 +136,8 @@ in { def publish(args, user, topic="${topic}", port=${toString port}): return "{} {}".format(mosquitto_cmd("pub", user, topic, port), args) - def subscribe(args, user, topic="${topic}", port=${toString port}): - return "{} -C 1 {}".format(mosquitto_cmd("sub", user, topic, port), args) + return "{} -W 5 -C 1 {}".format(mosquitto_cmd("sub", user, topic, port), args) def parallel(*fns): from threading import Thread @@ -150,17 +149,15 @@ in { start_all() server.wait_for_unit("mosquitto.service") - def check_passwords(): + with subtest("check passwords"): client1.succeed(publish("-m test", "password_store")) client1.succeed(publish("-m test", "password_file")) client1.succeed(publish("-m test", "hashed_store")) client1.succeed(publish("-m test", "hashed_file")) - check_passwords() - - def check_acl(): + with subtest("check acl"): client1.succeed(subscribe("", "reader", topic="$SYS/#")) - client1.fail(subscribe("-W 5", "writer", topic="$SYS/#")) + client1.fail(subscribe("", "writer", topic="$SYS/#")) parallel( lambda: client1.succeed(subscribe("-i 3688cdd7-aa07-42a4-be22-cb9352917e40", "reader")), @@ -170,15 +167,13 @@ in { ]) parallel( - lambda: client1.fail(subscribe("-W 5 -i 24ff16a2-ae33-4a51-9098-1b417153c712", "reader")), + lambda: client1.fail(subscribe("-i 24ff16a2-ae33-4a51-9098-1b417153c712", "reader")), lambda: [ server.wait_for_console_text("24ff16a2-ae33-4a51-9098-1b417153c712"), client2.succeed(publish("-m test", "reader")) ]) - check_acl() - - def check_tls(): + with subtest("check tls"): client1.succeed( subscribe( "--cafile ${snakeOil}/ca.crt " @@ -187,7 +182,5 @@ in { topic="$SYS/#", port=${toString tlsPort}, user="no_such_user")) - - check_tls() ''; })