summary refs log tree commit diff
path: root/nixos/tests
diff options
context:
space:
mode:
authorJos van Bakel <jos@codeaddict.org>2022-02-19 16:08:06 +0100
committerJos van Bakel <jos@codeaddict.org>2022-03-07 17:36:21 +0100
commitdaab8fb3af41b9310faa262791769ef22ee2a191 (patch)
treea9d9cd78e9f6a85bb3017083a44ad7680b920cd4 /nixos/tests
parent652aa6df2ca13c61a43341ee3f12cd8723d938e2 (diff)
downloadnixpkgs-daab8fb3af41b9310faa262791769ef22ee2a191.tar
nixpkgs-daab8fb3af41b9310faa262791769ef22ee2a191.tar.gz
nixpkgs-daab8fb3af41b9310faa262791769ef22ee2a191.tar.bz2
nixpkgs-daab8fb3af41b9310faa262791769ef22ee2a191.tar.lz
nixpkgs-daab8fb3af41b9310faa262791769ef22ee2a191.tar.xz
nixpkgs-daab8fb3af41b9310faa262791769ef22ee2a191.tar.zst
nixpkgs-daab8fb3af41b9310faa262791769ef22ee2a191.zip
nixos/nats: fix test
Diffstat (limited to 'nixos/tests')
-rw-r--r--nixos/tests/nats.nix24
1 files changed, 11 insertions, 13 deletions
diff --git a/nixos/tests/nats.nix b/nixos/tests/nats.nix
index bee36f262f4..c650904e53b 100644
--- a/nixos/tests/nats.nix
+++ b/nixos/tests/nats.nix
@@ -45,21 +45,19 @@ in import ./make-test-python.nix ({ pkgs, lib, ... }: {
             "{}"
         ).format(" ".join(args))
 
+    def parallel(*fns):
+        from threading import Thread
+        threads = [ Thread(target=fn) for fn in fns ]
+        for t in threads: t.start()
+        for t in threads: t.join()
+
     start_all()
     server.wait_for_unit("nats.service")
 
-    client1.fail("test -f ${file}")
-
-    # Subscribe on topic on client1 and echo messages to file.
-    client1.execute("({} | tee ${file} &)".format(nats_cmd("sub", "--raw", "${topic}")))
-
-    # Give client1 some time to subscribe.
-    client1.execute("sleep 2")
-
-    # Publish message on client2.
-    client2.execute(nats_cmd("pub", "${topic}", "hello"))
-
-    # Check if message has been received.
-    client1.succeed("grep -q hello ${file}")
+    with subtest("pub sub"):
+        parallel(
+            lambda: client1.succeed(nats_cmd("sub", "--count", "1", "${topic}")),
+            lambda: client2.succeed("sleep 2 && {}".format(nats_cmd("pub", "${topic}", "hello"))),
+        )
   '';
 })