git.iko.soy/typeable/nixpkgs
on master help sign in
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.

commit70d64d129e9406c943b24f316689eafd400e3280 authorMaximilian Bosch <maximilian@mbosch.me> dateWed 16 May 2018, 18:03 (9 years ago) parent9788459
1 file changed+15−4
nixos/tests/statsd.nix+15−4
nixos/tests/statsd.nix+15−4
@@ -8,7 +8,7 @@ with lib;
88 maintainers = [ ma27 ];
99 };
1010
11− nodes.statsd1 = {
11+ machine = {
1212 services.statsd.enable = true;
1313 services.statsd.backends = [ "statsd-influxdb-backend" "console" ];
1414 services.statsd.extraConfig = ''
@@ -33,8 +33,19 @@ with lib;
3333 };
3434
3535 testScript = ''
36− $statsd1->start();
37− $statsd1->waitForUnit("statsd.service");
38− $statsd1->waitUntilSucceeds("nc -z 127.0.0.1 8126");
36+ $machine->start();
37+ $machine->waitForUnit("statsd.service");
38+ $machine->waitForOpenPort(8126);
39+
40+ # check state of the `statsd` server
41+ $machine->succeed('[ "health: up" = "$(echo health | nc 127.0.0.1 8126 -w 120 -N)" ];');
42+
43+ # confirm basic examples for metrics derived from docs:
44+ # https://github.com/etsy/statsd/blob/v0.8.0/README.md#usage and
45+ # https://github.com/etsy/statsd/blob/v0.8.0/docs/admin_interface.md
46+ $machine->succeed("echo 'foo:1|c' | nc -u -w 0 127.0.0.1 8125");
47+ $machine->succeed("echo counters | nc -w 120 127.0.0.1 8126 -N | grep foo");
48+ $machine->succeed("echo 'delcounters foo' | nc -w 120 127.0.0.1 8126 -N");
49+ $machine->fail("echo counters | nc -w 120 127.0.0.1 8126 -N | grep foo");
3950 '';
4051})