summary refs log tree commit diff
path: root/nixos/tests
diff options
context:
space:
mode:
authorMaximilian Bosch <maximilian@mbosch.me>2018-05-16 18:03:55 +0200
committerxeji <36407913+xeji@users.noreply.github.com>2018-05-16 18:03:55 +0200
commit70d64d129e9406c943b24f316689eafd400e3280 (patch)
tree283401a4a35271df12b94dc9cbd9fb2dee690541 /nixos/tests
parent978845967858c9edb544484bc97d152bc2ffab44 (diff)
downloadnixpkgs-70d64d129e9406c943b24f316689eafd400e3280.tar
nixpkgs-70d64d129e9406c943b24f316689eafd400e3280.tar.gz
nixpkgs-70d64d129e9406c943b24f316689eafd400e3280.tar.bz2
nixpkgs-70d64d129e9406c943b24f316689eafd400e3280.tar.lz
nixpkgs-70d64d129e9406c943b24f316689eafd400e3280.tar.xz
nixpkgs-70d64d129e9406c943b24f316689eafd400e3280.tar.zst
nixpkgs-70d64d129e9406c943b24f316689eafd400e3280.zip
nixos/statsd: refactor test (#40554)
`statsd` is a daemon written in `node` to gather statistics over UDP.
The current test ensures that a port is open, but the basic
functionality isn't sufficiently tested.

This patch contains the following changes:

* Simplified port scanning (`waitForOpenPort` rather than `netcat` magic).

* Issue a TCP command to check the health of the `statsd` server.

* Simple script to check if `statsd` receives data over UDP and confirms
  the basic functionality of the TCP interface on `8126` for admin
  purposes.
Diffstat (limited to 'nixos/tests')
-rw-r--r--nixos/tests/statsd.nix19
1 files changed, 15 insertions, 4 deletions
diff --git a/nixos/tests/statsd.nix b/nixos/tests/statsd.nix
index c71949249a4..666961249ce 100644
--- a/nixos/tests/statsd.nix
+++ b/nixos/tests/statsd.nix
@@ -8,7 +8,7 @@ with lib;
     maintainers = [ ma27 ];
   };
 
-  nodes.statsd1 = {
+  machine = {
     services.statsd.enable = true;
     services.statsd.backends = [ "statsd-influxdb-backend" "console" ];
     services.statsd.extraConfig = ''
@@ -33,8 +33,19 @@ with lib;
   };
 
   testScript = ''
-    $statsd1->start();
-    $statsd1->waitForUnit("statsd.service");
-    $statsd1->waitUntilSucceeds("nc -z 127.0.0.1 8126");
+    $machine->start();
+    $machine->waitForUnit("statsd.service");
+    $machine->waitForOpenPort(8126);
+
+    # check state of the `statsd` server
+    $machine->succeed('[ "health: up" = "$(echo health | nc 127.0.0.1 8126 -w 120 -N)" ];');
+
+    # confirm basic examples for metrics derived from docs:
+    # https://github.com/etsy/statsd/blob/v0.8.0/README.md#usage and
+    # https://github.com/etsy/statsd/blob/v0.8.0/docs/admin_interface.md
+    $machine->succeed("echo 'foo:1|c' | nc -u -w 0  127.0.0.1 8125");
+    $machine->succeed("echo counters | nc -w 120 127.0.0.1 8126 -N | grep foo");
+    $machine->succeed("echo 'delcounters foo' | nc -w 120 127.0.0.1 8126 -N");
+    $machine->fail("echo counters | nc -w 120 127.0.0.1 8126 -N | grep foo");
   '';
 })