From 3238496b3d771c1310bd456ef06303556186b181 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Tue, 14 Dec 2021 20:25:02 -0500 Subject: [PATCH] t/Setup: move subs calling hydra-* programs to a CliPrograms module Makes it so HydraTestContext can call them without an import loop --- t/lib/CliRunners.pm | 50 +++++++++++++++++++++++++++++++++++++++++++++ t/lib/Setup.pm | 40 +----------------------------------- 2 files changed, 51 insertions(+), 39 deletions(-) create mode 100644 t/lib/CliRunners.pm diff --git a/t/lib/CliRunners.pm b/t/lib/CliRunners.pm new file mode 100644 index 00000000..f857d468 --- /dev/null +++ b/t/lib/CliRunners.pm @@ -0,0 +1,50 @@ +use warnings; +use strict; + +package CliRunners; +our @ISA = qw(Exporter); +our @EXPORT = qw( + evalSucceeds runBuild sendNotifications + captureStdoutStderr); + + +sub captureStdoutStderr { + # "Lazy"-load Hydra::Helper::Nix to avoid the compile-time + # import of Hydra::Model::DB. Early loading of the DB class + # causes fixation of the DSN, and we need to fixate it after + # the temporary DB is setup. + require Hydra::Helper::Nix; + return Hydra::Helper::Nix::captureStdoutStderr(@_) +} + +sub evalSucceeds { + my ($jobset) = @_; + my ($res, $stdout, $stderr) = captureStdoutStderr(60, ("hydra-eval-jobset", $jobset->project->name, $jobset->name)); + $jobset->discard_changes; # refresh from DB + chomp $stdout; chomp $stderr; + print STDERR "Evaluation errors for jobset ".$jobset->project->name.":".$jobset->name.": \n".$jobset->errormsg."\n" if $jobset->errormsg; + print STDERR "STDOUT: $stdout\n" if $stdout ne ""; + print STDERR "STDERR: $stderr\n" if $stderr ne ""; + return !$res; +} + +sub runBuild { + my ($build) = @_; + my ($res, $stdout, $stderr) = captureStdoutStderr(60, ("hydra-queue-runner", "-vvvv", "--build-one", $build->id)); + if ($res) { + print STDERR "Queue runner stdout: $stdout\n" if $stdout ne ""; + print STDERR "Queue runner stderr: $stderr\n" if $stderr ne ""; + } + return !$res; +} + +sub sendNotifications() { + my ($res, $stdout, $stderr) = captureStdoutStderr(60, ("hydra-notify", "--queued-only")); + if ($res) { + print STDERR "hydra notify stdout: $stdout\n" if $stdout ne ""; + print STDERR "hydra notify stderr: $stderr\n" if $stderr ne ""; + } + return !$res; +} + +1; diff --git a/t/lib/Setup.pm b/t/lib/Setup.pm index 3887784c..d0f0230b 100644 --- a/t/lib/Setup.pm +++ b/t/lib/Setup.pm @@ -8,6 +8,7 @@ use File::Temp; use File::Path qw(make_path); use File::Basename; use Cwd qw(abs_path getcwd); +use CliRunners; our @ISA = qw(Exporter); our @EXPORT = qw(test_context test_init hydra_setup write_file nrBuildsForJobset queuedBuildsForJobset @@ -45,15 +46,6 @@ sub write_file { close $fh; } -sub captureStdoutStderr { - # "Lazy"-load Hydra::Helper::Nix to avoid the compile-time - # import of Hydra::Model::DB. Early loading of the DB class - # causes fixation of the DSN, and we need to fixate it after - # the temporary DB is setup. - require Hydra::Helper::Nix; - return Hydra::Helper::Nix::captureStdoutStderr(@_) -} - sub hydra_setup { my ($db) = @_; $db->resultset('Users')->create({ username => "root", emailaddress => 'root@invalid.org', password => '' }); @@ -103,36 +95,6 @@ sub createJobsetWithOneInput { return $jobset; } -sub evalSucceeds { - my ($jobset) = @_; - my ($res, $stdout, $stderr) = captureStdoutStderr(60, ("hydra-eval-jobset", $jobset->project->name, $jobset->name)); - $jobset->discard_changes; # refresh from DB - chomp $stdout; chomp $stderr; - print STDERR "Evaluation errors for jobset ".$jobset->project->name.":".$jobset->name.": \n".$jobset->errormsg."\n" if $jobset->errormsg; - print STDERR "STDOUT: $stdout\n" if $stdout ne ""; - print STDERR "STDERR: $stderr\n" if $stderr ne ""; - return !$res; -} - -sub runBuild { - my ($build) = @_; - my ($res, $stdout, $stderr) = captureStdoutStderr(60, ("hydra-queue-runner", "-vvvv", "--build-one", $build->id)); - if ($res) { - print STDERR "Queue runner stdout: $stdout\n" if $stdout ne ""; - print STDERR "Queue runner stderr: $stderr\n" if $stderr ne ""; - } - return !$res; -} - -sub sendNotifications() { - my ($res, $stdout, $stderr) = captureStdoutStderr(60, ("hydra-notify", "--queued-only")); - if ($res) { - print STDERR "hydra notify stdout: $stdout\n" if $stdout ne ""; - print STDERR "hydra notify stderr: $stderr\n" if $stderr ne ""; - } - return !$res; -} - sub updateRepository { my ($scm, $update, $scratchdir) = @_; my $curdir = getcwd;