Permalink
Browse files

Generic test suite for statsd daemons

It's already working for our implementation and the nodejs one!
Very exciting. Tests are passed by both, and I've found
a couple of very subtle bugs in Net::Statsd::Server.
  • Loading branch information...
1 parent f59842f commit 6a4e97c32c3c909a0c0e6ae957657e29f0871de1 @cosimo committed Jan 28, 2013
View
@@ -0,0 +1,22 @@
+{
+ "address": "0.0.0.0",
+ "port": 40001,
+ "mgmt_address": "0.0.0.0",
+ "mgmt_port": 40002,
+
+ "debug": false,
+ "dumpMessages": false,
+ "flushInterval": 1000,
+
+ "log" : {
+ "backend": "stdout",
+ "level": "LOG_INFO",
+ },
+
+ "backends": [ "./backends/console", "./backends/graphite" ],
+ "graphiteHost": "localhost",
+ "graphitePort": 2003,
+ "graphite": {
+ "legacyNamespace": false
+ }
+}
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+
+use 5.010;
+use strict;
+use warnings;
+
+use FindBin qw($Bin);
+use Test::Statsd;
+use Test::More;
+
+my $t = Test::Statsd->new({
+ binary => $ENV{STATSD_BINARY} // "$Bin/../../bin/statsd",
+ config => $ENV{STATSD_CONFIG} // "$Bin/../config/testConfig.js",
+});
+
+$t->start_statsd();
+$t->send_udp(localhost=>40001, "a_bad_test_value|z");
+# Will wait until it receives the graphite flush
+my $stats = $t->wait_and_collect_flush_data();
+$t->stop_statsd();
+
+ok($stats, "Should receive some data");
+
+$stats = $t->hashify($stats);
+ok(exists $stats->{"stats.statsd.numStats"},
+ "Got back 'stats.statsd.numStats'");
+
+is($stats->{"stats.statsd.numStats"} => 2,
+ "There should only be two stats, since we sent a bad message");
+
+is($stats->{"stats.counters.statsd.bad_lines_seen.count"} => 1,
+ "Backend recognised our bad message bumping 'bad_lines_seen'");
+
+done_testing;
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+
+use 5.010;
+use strict;
+use warnings;
+
+use FindBin qw($Bin);
+use Test::Statsd;
+use Test::More;
+
+plan tests => 4;
+
+my $t = Test::Statsd->new({
+ binary => $ENV{STATSD_BINARY} // "$Bin/../../bin/statsd",
+ config => $ENV{STATSD_CONFIG} // "$Bin/../config/testConfig.js",
+});
+
+$t->start_statsd();
+
+my $test_value = 100;
+$t->send_udp(localhost=>40001, "a_test_value:${test_value}|c");
+
+# Will wait until it receives the graphite flush
+my $stats = $t->wait_and_collect_flush_data();
+ok($stats, "Should receive some data");
+
+diag($stats);
+
+$t->stop_statsd();
+$stats = $t->hashify($stats);
+
+is($stats->{"stats.statsd.numStats"} => 3,
+ "Got the one metric that was fired");
+
+my $flush_interval = 1000; # ms
+my $expected_rate = ($test_value / ($flush_interval / 1000));
+
+ok($stats->{"stats.counters.a_test_value.rate"} == $expected_rate,
+ "Rate of counter is calculated according to flushInterval");
+
+ok($stats->{"stats.counters.a_test_value.count"} == $test_value,
+ "Counter cumulative value should be the sum of all values sent");
@@ -0,0 +1,36 @@
+#!/usr/bin/perl
+
+use 5.010;
+use strict;
+use warnings;
+
+use FindBin qw($Bin);
+use Test::Statsd;
+use Test::More;
+
+plan tests => 3;
+
+my $t = Test::Statsd->new({
+ binary => $ENV{STATSD_BINARY} // "$Bin/../../bin/statsd",
+ config => $ENV{STATSD_CONFIG} // "$Bin/../config/testConfig.js",
+});
+
+$t->start_statsd();
+
+my $test_value = 100;
+$t->send_udp(localhost=>40001, "a_test_value:${test_value}|ms");
+
+# Will wait until it receives the graphite flush
+my $stats = $t->wait_and_collect_flush_data();
+ok($stats, "Should receive some data");
+
+diag($stats);
+
+$t->stop_statsd();
+$stats = $t->hashify($stats);
+
+is($stats->{"stats.statsd.numStats"} => 3,
+ "Got the one metric that was fired");
+
+ok($stats->{"stats.timers.a_test_value.mean_90"} == $test_value,
+ "stats.timers.a_test_value.mean_90 should be ${test_value}");

0 comments on commit 6a4e97c

Please sign in to comment.