From 6f662a606abe02c1c4918742c21eeec772e8fcfc Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sat, 20 Mar 2021 09:06:54 -0400 Subject: [PATCH 1/3] hydra-send-stats: add a failing test asserting it can run --- t/lib/Setup.pm | 5 ++++- t/scripts/hydra-send-stats.t | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 t/scripts/hydra-send-stats.t diff --git a/t/lib/Setup.pm b/t/lib/Setup.pm index 3cc9828e..cdea38ce 100644 --- a/t/lib/Setup.pm +++ b/t/lib/Setup.pm @@ -9,7 +9,10 @@ use File::Basename; use Cwd qw(abs_path getcwd); our @ISA = qw(Exporter); -our @EXPORT = qw(test_init hydra_setup nrBuildsForJobset queuedBuildsForJobset nrQueuedBuildsForJobset createBaseJobset createJobsetWithOneInput evalSucceeds runBuild sendNotifications updateRepository); +our @EXPORT = qw(test_init hydra_setup nrBuildsForJobset queuedBuildsForJobset + nrQueuedBuildsForJobset createBaseJobset createJobsetWithOneInput + evalSucceeds runBuild sendNotifications updateRepository + captureStdoutStderr); # Set up the environment for running tests. # diff --git a/t/scripts/hydra-send-stats.t b/t/scripts/hydra-send-stats.t new file mode 100644 index 00000000..174bde64 --- /dev/null +++ b/t/scripts/hydra-send-stats.t @@ -0,0 +1,20 @@ +use feature 'unicode_strings'; +use strict; +use Setup; + +my %ctx = test_init(); + +require Hydra::Schema; +require Hydra::Model::DB; + +use Test2::V0; + +my $db = Hydra::Model::DB->new; +hydra_setup($db); + +my ($res, $stdout, $stderr) = captureStdoutStderr(60, ("hydra-send-stats")); +is($stdout, "", "hydra-send-stats stdout should be empty"); +is($stderr, "", "hydra-send-stats stderr should be empty"); +is($res, 0, "hydra-send-stats --once should exit zero"); + +done_testing; From 6bb180a0f2c136375d6d2fe5ae441a7c0f949b90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 20 Mar 2021 06:57:37 +0100 Subject: [PATCH 2/3] hydra-send-stats: fix imports --- src/script/hydra-send-stats | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/script/hydra-send-stats b/src/script/hydra-send-stats index 8c7d2cd5..ee047276 100755 --- a/src/script/hydra-send-stats +++ b/src/script/hydra-send-stats @@ -2,6 +2,7 @@ use strict; use utf8; +use Hydra::Helper::Nix; use Net::Statsd; use File::Slurp; use JSON; @@ -10,7 +11,7 @@ STDERR->autoflush(1); binmode STDERR, ":encoding(utf8)"; my $config = getHydraConfig(); -my $statsdConfig = Hydra::Helper::Nix::getStatsdConfig($config); +my $statsdConfig = getStatsdConfig($config); $Net::Statsd::HOST = $statsdConfig->{'host'}; $Net::Statsd::PORT = $statsdConfig->{'port'}; From 425c7ff17f2f801894902184fb4b39f14c944d55 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sat, 20 Mar 2021 09:12:02 -0400 Subject: [PATCH 3/3] hydra-send-stats: add a --once option for testing --- src/script/hydra-send-stats | 24 ++++++++++++++++++++++++ t/scripts/hydra-send-stats.t | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/script/hydra-send-stats b/src/script/hydra-send-stats index ee047276..d07d9406 100755 --- a/src/script/hydra-send-stats +++ b/src/script/hydra-send-stats @@ -6,6 +6,7 @@ use Hydra::Helper::Nix; use Net::Statsd; use File::Slurp; use JSON; +use Getopt::Long qw(:config gnu_getopt); STDERR->autoflush(1); binmode STDERR, ":encoding(utf8)"; @@ -65,6 +66,26 @@ sub sendQueueRunnerStats { gauge("hydra.queue.machines.in_use", scalar(grep { $_->{currentJobs} > 0 } (values %{$json->{machines}}))); } + +sub showHelp { + print < \$once, + "help" => sub { showHelp() } + ) or exit 1; + while (1) { eval { sendQueueRunnerStats(); @@ -78,5 +99,8 @@ while (1) { gauge("hydra.mem.dirty", $dirty); } + if ($once) { + last; + } sleep(30); } diff --git a/t/scripts/hydra-send-stats.t b/t/scripts/hydra-send-stats.t index 174bde64..dde88cfe 100644 --- a/t/scripts/hydra-send-stats.t +++ b/t/scripts/hydra-send-stats.t @@ -12,7 +12,7 @@ use Test2::V0; my $db = Hydra::Model::DB->new; hydra_setup($db); -my ($res, $stdout, $stderr) = captureStdoutStderr(60, ("hydra-send-stats")); +my ($res, $stdout, $stderr) = captureStdoutStderr(60, ("hydra-send-stats", "--once")); is($stdout, "", "hydra-send-stats stdout should be empty"); is($stderr, "", "hydra-send-stats stderr should be empty"); is($res, 0, "hydra-send-stats --once should exit zero");