Attempt to fix errors during test teardown
[?]
Dec 8, 2021, 6:31 PM
OSIBECOEJH25QAXCZ76PY7OTP3STBNWEUC36WRTNYAN3IIJP5ZQQCDependencies
- [2]
YIZWKGFItests: add jobsdir and testdir to ctx hash - [3]
I7UFBBQGSetup.pm: specify NIX_ env vars for running yath - [4]
PVKBPA7ZDocument the use_external_destination_store test_init param - [5]
3JD6P6FHt/lib/Setup.pm: nix_config: default to empty string - [6]
LYRHVDS2TT: add helpers for linking to jobs, jobsets, and projects, and for generating colon separated names. - [7]
HE3GX5IPOptimize fetch-git. - [8]
4WLW4VHSTest setup: support arbitrary hydra config - [9]
C66VQYWTRun the tests with a remote dest store - [10]
4QI6G7YBtests: replace the flat list of contexts with a hash - [11]
U2PHPVGDt/Setup.pm: sort NIX_ env vars - [12]
UIA3ULNUGive each test its own Nix directories - [13]
OWRS526HCreate an ephemeral PostgreSQL database per test - [14]
HX4QYOYAadd first evaluations tests - [15]
CSNQ6TCFDrop references to NIX_MANFIESTS_DIR and NIX_BUILD_HOOK - [16]
2I3HFWBKtests: Make the external destination store optional - [17]
HXEZUCTDAdd test to verify includes work - [18]
DNOLOMX7hydra-send-stats: add a failing test asserting it can run - [19]
7I2U2MHUperlcritic: use strict, use warnings - [20]
ZY6CMDJYfixup: TT.t: move the :'s to the next line - [21]
3AKZKWCRRunCommand: Test - [22]
FAIJDQKZ - [23]
6HYCG3DCtests: allow specifying some nix config - [24]
5TJXSY4CTT.t: fixup $_, since _ is a special variable, not a throwaway - [*]
2JJP7673tests: move to t, allow `yath test` from root
Change contents
- edit in t/View/TT.t at line 5
use Test2::V0; - replacement in t/View/TT.t at line 7
my %ctx = test_init();my $ctx = test_context(); - edit in t/View/TT.t at line 9
require Hydra::Schema;require Hydra::Model::DB;use Test2::V0; - replacement in t/View/TT.t at line 10
require Hydra::View::TT;require Catalyst::Test; - replacement in t/View/TT.t at line 13
my $db = Hydra::Model::DB->new;hydra_setup($db);my $db = $ctx->db; - edit in t/View/TT.t at line 15
require Hydra::View::TT; - edit in t/View/TT.t at line 18
require Catalyst::Test; - replacement in t/View/TT.t at line 23
my $jobset = createBaseJobset("example", "bogus.nix", $ctx{jobsdir});my $jobset = createBaseJobset("example", "bogus.nix", $ctx->jobsdir); - edit in t/evaluate-basic.t at line 5
my %ctx = test_init();require Hydra::Schema;require Hydra::Model::DB; - replacement in t/evaluate-basic.t at line 7
my $db = Hydra::Model::DB->new;hydra_setup($db);my $ctx = test_context();my $db = $ctx->db; - replacement in t/evaluate-basic.t at line 13
my $jobset = createBaseJobset("basic", "basic.nix", $ctx{jobsdir});my $jobset = createBaseJobset("basic", "basic.nix", $ctx->jobsdir); - file addition: HydraTestContext.pm[26.2459]
use strict;use warnings;package HydraTestContext;use File::Path qw(make_path);use File::Basename;use Cwd qw(abs_path getcwd);# Set up the environment for running tests.## Hash Parameters:## * hydra_config: configuration for the Hydra processes for your test.# * nix_config: text to include in the test's nix.conf# * use_external_destination_store: Boolean indicating whether hydra should# use a destination store different from the evaluation store.# True by default.## This clears several environment variables and sets them to ephemeral# values: a temporary database, temporary Nix store, temporary Hydra# data directory, etc.## Note: This function must run _very_ early, before nearly any Hydra# libraries are loaded. To use this, you very likely need to `use Setup`# and then run `test_init`, and then `require` the Hydra libraries you# need.## It returns a tuple: a handle to a temporary directory and a handle to# the postgres service. If either of these variables go out of scope,# those resources are released and the test environment becomes invalid.## Look at the top of an existing `.t` file to see how this should be used# in practice.sub new {my ($class, %opts) = @_;my $dir = File::Temp->newdir();$ENV{'HYDRA_DATA'} = "$dir/hydra-data";mkdir $ENV{'HYDRA_DATA'};$ENV{'NIX_CONF_DIR'} = "$dir/nix/etc/nix";make_path($ENV{'NIX_CONF_DIR'});my $nixconf = "$ENV{'NIX_CONF_DIR'}/nix.conf";my $nix_config = "sandbox = false\n" . ($opts{'nix_config'} || "");write_file($nixconf, $nix_config);$ENV{'HYDRA_CONFIG'} = "$dir/hydra.conf";my $hydra_config = $opts{'hydra_config'} || "";if ($opts{'use_external_destination_store'} // 1) {$hydra_config = "store_uri = file:$dir/nix/dest-store\n" . $hydra_config;}write_file($ENV{'HYDRA_CONFIG'}, $hydra_config);$ENV{'NIX_LOG_DIR'} = "$dir/nix/var/log/nix";$ENV{'NIX_REMOTE_SYSTEMS'} = '';$ENV{'NIX_REMOTE'} = '';$ENV{'NIX_STATE_DIR'} = "$dir/nix/var/nix";$ENV{'NIX_STORE_DIR'} = "$dir/nix/store";my $pgsql = Test::PostgreSQL->new(extra_initdb_args => "--locale C.UTF-8");$ENV{'HYDRA_DBI'} = $pgsql->dsn;system("hydra-init") == 0 or die;my $self = {_db => undef,db_handle => $pgsql,tmpdir => $dir,testdir => abs_path(dirname(__FILE__) . "/.."),jobsdir => abs_path(dirname(__FILE__) . "/../jobs")};return bless $self, $class;}sub db {my ($self, $setup) = @_;if (!defined $self->{_db}) {require Hydra::Schema;require Hydra::Model::DB;$self->{_db} = Hydra::Model::DB->new();if (!(defined $setup && $setup == 0)) {$self->{_db}->resultset('Users')->create({username => "root",emailaddress => 'root@invalid.org',password => ''});}}return $self->{_db};}sub tmpdir {my ($self) = @_;return $self->{tmpdir};}sub testdir {my ($self) = @_;return $self->{testdir};}sub jobsdir {my ($self) = @_;return $self->{jobsdir};}sub DESTROY{my ($self) = @_;$self->db(0)->schema->storage->disconnect();}sub write_file {my ($path, $text) = @_;open(my $fh, '>', $path) or die "Could not open file '$path' $!";print $fh $text || "";close $fh;}1; - replacement in t/lib/Setup.pm at line 13
our @EXPORT = qw(test_init hydra_setup write_file nrBuildsForJobset queuedBuildsForJobsetour @EXPORT = qw(test_context test_init hydra_setup write_file nrBuildsForJobset queuedBuildsForJobset - replacement in t/lib/Setup.pm at line 20
# Hash Parameters:# See HydraTestContext::new for documentationsub test_context {require HydraTestContext;return HydraTestContext->new(@_);}# Set up the environment for running tests. - replacement in t/lib/Setup.pm at line 28[7.67]→[7.67:139](∅→∅),[7.139]→[7.0:56](∅→∅),[7.56]→[4.0:171](∅→∅),[7.56]→[7.139:835](∅→∅),[4.171]→[7.139:835](∅→∅),[7.139]→[7.139:835](∅→∅)
# * hydra_config: configuration for the Hydra processes for your test.# * nix_config: text to include in the test's nix.conf# * use_external_destination_store: Boolean indicating whether hydra should# use a destination store different from the evaluation store.# True by default.## This clears several environment variables and sets them to ephemeral# values: a temporary database, temporary Nix store, temporary Hydra# data directory, etc.## Note: This function must run _very_ early, before nearly any Hydra# libraries are loaded. To use this, you very likely need to `use Setup`# and then run `test_init`, and then `require` the Hydra libraries you# need.## It returns a tuple: a handle to a temporary directory and a handle to# the postgres service. If either of these variables go out of scope,# those resources are released and the test environment becomes invalid.## Look at the top of an existing `.t` file to see how this should be used# in practice.# See HydraTestContext::new for documentation - replacement in t/lib/Setup.pm at line 30[7.851]→[7.851:871](∅→∅),[7.871]→[7.1521:1767](∅→∅),[7.1521]→[7.1521:1767](∅→∅),[7.1767]→[5.0:72](∅→∅),[5.72]→[7.640:679](∅→∅),[7.640]→[7.640:679](∅→∅),[7.679]→[7.873:919](∅→∅),[7.873]→[7.873:919](∅→∅)
my %opts = @_;my $dir = File::Temp->newdir();$ENV{'HYDRA_DATA'} = "$dir/hydra-data";mkdir $ENV{'HYDRA_DATA'};$ENV{'NIX_CONF_DIR'} = "$dir/nix/etc/nix";make_path($ENV{'NIX_CONF_DIR'});my $nixconf = "$ENV{'NIX_CONF_DIR'}/nix.conf";my $nix_config = "sandbox = false\n" . ($opts{'nix_config'} || "");write_file($nixconf, $nix_config);$ENV{'HYDRA_CONFIG'} = "$dir/hydra.conf";require HydraTestContext;my $ctx = HydraTestContext->new(@_); - edit in t/lib/Setup.pm at line 33[7.1894]→[7.680:732](∅→∅),[7.732]→[7.0:56](∅→∅),[7.1026]→[7.0:56](∅→∅),[7.56]→[7.733:815](∅→∅),[7.815]→[7.115:121](∅→∅),[7.115]→[7.115:121](∅→∅),[7.121]→[7.816:870](∅→∅),[7.870]→[7.1084:1085](∅→∅),[7.1084]→[7.1084:1085](∅→∅),[7.1085]→[7.0:50](∅→∅),[7.50]→[3.0:66](∅→∅),[7.50]→[7.1894:1942](∅→∅),[3.66]→[7.1894:1942](∅→∅),[7.1085]→[7.1894:1942](∅→∅),[7.1894]→[7.1894:1942](∅→∅),[7.2005]→[7.2005:2051](∅→∅),[7.2101]→[7.2101:2196](∅→∅),[7.2196]→[7.821:896](∅→∅),[7.821]→[7.821:896](∅→∅)
my $hydra_config = $opts{'hydra_config'} || "";if ($opts{'use_external_destination_store'} // 1) {$hydra_config = "store_uri = file:$dir/nix/dest-store\n" . $hydra_config;}write_file($ENV{'HYDRA_CONFIG'}, $hydra_config);$ENV{'NIX_LOG_DIR'} = "$dir/nix/var/log/nix";$ENV{'NIX_REMOTE_SYSTEMS'} = '';$ENV{'NIX_REMOTE'} = '';$ENV{'NIX_STATE_DIR'} = "$dir/nix/var/nix";$ENV{'NIX_STORE_DIR'} = "$dir/nix/store";my $pgsql = Test::PostgreSQL->new(extra_initdb_args => "--locale C.UTF-8");$ENV{'HYDRA_DBI'} = $pgsql->dsn;system("hydra-init") == 0 or die; - replacement in t/lib/Setup.pm at line 34[7.85]→[2.1331:1353](∅→∅),[2.1353]→[7.85:109](∅→∅),[7.85]→[7.85:109](∅→∅),[7.109]→[2.1354:1470](∅→∅),[2.1470]→[7.130:137](∅→∅),[7.130]→[7.130:137](∅→∅)
db => $pgsql,tmpdir => $dir,testdir => abs_path(dirname(__FILE__) . "/.."),jobsdir => abs_path(dirname(__FILE__) . "/../jobs"));context => $ctx,tmpdir => $ctx->tmpdir,testdir => $ctx->testdir,jobsdir => $ctx->jobsdir)