captureStdoutStderr*: move to Hydra::Helper::Exec which helps avoid some environment variable fixation problems

This commit is contained in:
Graham Christensen
2022-02-09 13:40:51 -05:00
parent 1abe7f4d80
commit 845e6d4760
16 changed files with 54 additions and 50 deletions

View File

@ -6,13 +6,13 @@ use IO::Uncompress::Bunzip2 qw(bunzip2);
use Archive::Tar;
use JSON::MaybeXS qw(decode_json);
use Data::Dumper;
use Hydra::Helper::Exec;
my %ctx = test_init(
use_external_destination_store => 0
);
require Hydra::Schema;
require Hydra::Model::DB;
require Hydra::Helper::Nix;
use Test2::V0;
require Catalyst::Test;
@ -47,7 +47,7 @@ $tar->extract_file("channel/default.nix", $defaultnix);
print STDERR $tar->get_content("channel/default.nix");
(my $status, my $stdout, my $stderr) = Hydra::Helper::Nix::captureStdoutStderr(5, "nix-env", "--json", "--query", "--available", "--attr-path", "--file", $defaultnix);
(my $status, my $stdout, my $stderr) = captureStdoutStderr(5, "nix-env", "--json", "--query", "--available", "--attr-path", "--file", $defaultnix);
is($stderr, "", "Stderr should be empty");
is($status, 0, "Querying the packages should succeed");

View File

@ -13,6 +13,8 @@ my %ctx = test_init(
require Hydra::Schema;
require Hydra::Model::DB;
require Hydra::Helper::Nix;
use Test2::V0;

View File

@ -2,35 +2,15 @@ use warnings;
use strict;
package CliRunners;
use Hydra::Helper::Exec;
our @ISA = qw(Exporter);
our @EXPORT = qw(
captureStdoutStderr
captureStdoutStderrWithStdin
evalFails
evalSucceeds
runBuild
sendNotifications
);
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 captureStdoutStderrWithStdin {
# "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::captureStdoutStderrWithStdin(@_)
}
sub evalSucceeds {
my ($jobset) = @_;
my ($res, $stdout, $stderr) = captureStdoutStderr(60, ("hydra-eval-jobset", $jobset->project->name, $jobset->name));

View File

@ -8,12 +8,11 @@ use File::Temp;
use File::Path qw(make_path);
use File::Basename;
use Cwd qw(abs_path getcwd);
use Hydra::Helper::Exec;
use CliRunners;
our @ISA = qw(Exporter);
our @EXPORT = qw(
captureStdoutStderr
captureStdoutStderrWithStdin
createBaseJobset
createJobsetWithOneInput
evalFails

View File

@ -3,10 +3,14 @@ use warnings;
use Setup;
use Data::Dumper;
use Test2::V0;
use Hydra::Helper::Exec;
my $ctx = test_context(
use_external_destination_store => 1
);
require Hydra::Helper::Nix;
# This test is regarding https://github.com/NixOS/hydra/pull/1126
#
# A hydra instance was regularly failing to build derivations with:

View File

@ -2,6 +2,7 @@ use strict;
use warnings;
use Setup;
use Test2::V0;
use Hydra::Helper::Exec;
my $ctx = test_context();
my $db = $ctx->db();

View File

@ -2,6 +2,7 @@ use feature 'unicode_strings';
use strict;
use warnings;
use Setup;
use Hydra::Helper::Exec;
my %ctx = test_init();

View File

@ -2,6 +2,7 @@ use feature 'unicode_strings';
use strict;
use warnings;
use Setup;
use Hydra::Helper::Exec;
my %ctx = test_init();

View File

@ -3,6 +3,7 @@ use strict;
use warnings;
use Setup;
use Test2::V0;
use Hydra::Helper::Exec;
my $ctx = test_context();
my $builds = $ctx->makeAndEvaluateJobset(