Merge pull request #73827 from tfc/mosquitto-test-python
Mosquitto test python
This commit is contained in:
commit
0f2635b7d4
2 changed files with 37 additions and 35 deletions
|
@ -749,7 +749,7 @@ def run_tests() -> None:
|
||||||
if tests is not None:
|
if tests is not None:
|
||||||
with log.nested("running the VM test script"):
|
with log.nested("running the VM test script"):
|
||||||
try:
|
try:
|
||||||
exec(tests)
|
exec(tests, globals())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
eprint("error: {}".format(str(e)))
|
eprint("error: {}".format(str(e)))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -1,21 +1,10 @@
|
||||||
import ./make-test.nix ({ pkgs, ... }:
|
import ./make-test-python.nix ({ pkgs, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
port = 1888;
|
port = 1888;
|
||||||
username = "mqtt";
|
username = "mqtt";
|
||||||
password = "VERY_secret";
|
password = "VERY_secret";
|
||||||
topic = "test/foo";
|
topic = "test/foo";
|
||||||
|
|
||||||
cmd = bin: pkgs.lib.concatStringsSep " " [
|
|
||||||
"${pkgs.mosquitto}/bin/mosquitto_${bin}"
|
|
||||||
"-V mqttv311"
|
|
||||||
"-h server"
|
|
||||||
"-p ${toString port}"
|
|
||||||
"-u ${username}"
|
|
||||||
"-P '${password}'"
|
|
||||||
"-t ${topic}"
|
|
||||||
];
|
|
||||||
|
|
||||||
in {
|
in {
|
||||||
name = "mosquitto";
|
name = "mosquitto";
|
||||||
meta = with pkgs.stdenv.lib; {
|
meta = with pkgs.stdenv.lib; {
|
||||||
|
@ -49,40 +38,53 @@ in {
|
||||||
|
|
||||||
testScript = let
|
testScript = let
|
||||||
file = "/tmp/msg";
|
file = "/tmp/msg";
|
||||||
sub = args:
|
|
||||||
"(${cmd "sub"} -C 1 ${args} | tee ${file} &)";
|
|
||||||
in ''
|
in ''
|
||||||
startAll;
|
def mosquitto_cmd(binary):
|
||||||
$server->waitForUnit("mosquitto.service");
|
return (
|
||||||
|
"${pkgs.mosquitto}/bin/mosquitto_{} "
|
||||||
|
"-V mqttv311 "
|
||||||
|
"-h server "
|
||||||
|
"-p ${toString port} "
|
||||||
|
"-u ${username} "
|
||||||
|
"-P '${password}' "
|
||||||
|
"-t ${topic}"
|
||||||
|
).format(binary)
|
||||||
|
|
||||||
$server->fail("test -f ${file}");
|
|
||||||
$client1->fail("test -f ${file}");
|
|
||||||
$client2->fail("test -f ${file}");
|
|
||||||
|
|
||||||
|
def publish(args):
|
||||||
|
return "{} {}".format(mosquitto_cmd("pub"), args)
|
||||||
|
|
||||||
|
|
||||||
|
def subscribe(args):
|
||||||
|
return "({} -C 1 {} | tee ${file} &)".format(mosquitto_cmd("sub"), args)
|
||||||
|
|
||||||
|
|
||||||
|
start_all()
|
||||||
|
server.wait_for_unit("mosquitto.service")
|
||||||
|
|
||||||
|
for machine in server, client1, client2:
|
||||||
|
machine.fail("test -f ${file}")
|
||||||
|
|
||||||
# QoS = 0, so only one subscribers should get it
|
# QoS = 0, so only one subscribers should get it
|
||||||
$server->execute("${sub "-q 0"}");
|
server.execute(subscribe("-q 0"))
|
||||||
|
|
||||||
# we need to give the subscribers some time to connect
|
# we need to give the subscribers some time to connect
|
||||||
$client2->execute("sleep 5");
|
client2.execute("sleep 5")
|
||||||
$client2->succeed("${cmd "pub"} -m FOO -q 0");
|
client2.succeed(publish("-m FOO -q 0"))
|
||||||
|
|
||||||
$server->waitUntilSucceeds("grep -q FOO ${file}");
|
|
||||||
$server->execute("rm ${file}");
|
|
||||||
|
|
||||||
|
server.wait_until_succeeds("grep -q FOO ${file}")
|
||||||
|
server.execute("rm ${file}")
|
||||||
|
|
||||||
# QoS = 1, so both subscribers should get it
|
# QoS = 1, so both subscribers should get it
|
||||||
$server->execute("${sub "-q 1"}");
|
server.execute(subscribe("-q 1"))
|
||||||
$client1->execute("${sub "-q 1"}");
|
client1.execute(subscribe("-q 1"))
|
||||||
|
|
||||||
# we need to give the subscribers some time to connect
|
# we need to give the subscribers some time to connect
|
||||||
$client2->execute("sleep 5");
|
client2.execute("sleep 5")
|
||||||
$client2->succeed("${cmd "pub"} -m BAR -q 1");
|
client2.succeed(publish("-m BAR -q 1"))
|
||||||
|
|
||||||
$server->waitUntilSucceeds("grep -q BAR ${file}");
|
for machine in server, client1:
|
||||||
$server->execute("rm ${file}");
|
machine.wait_until_succeeds("grep -q BAR ${file}")
|
||||||
|
machine.execute("rm ${file}")
|
||||||
$client1->waitUntilSucceeds("grep -q BAR ${file}");
|
|
||||||
$client1->execute("rm ${file}");
|
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue