Give each test its own Nix directories

Otherwise we risk tripping over confusing statuses where a build is
"done" and "Cached", but we were expecting to run it.
This commit is contained in:
Graham Christensen
2021-02-22 16:52:38 -05:00
parent fe1f2f0806
commit 62b2880dfc
3 changed files with 59 additions and 19 deletions

View File

@ -3,16 +3,37 @@ package Setup;
use strict;
use Exporter;
use Test::PostgreSQL;
use File::Temp;
use File::Path qw(make_path);
use Cwd;
our @ISA = qw(Exporter);
our @EXPORT = qw(dbinit hydra_setup nrBuildsForJobset queuedBuildsForJobset nrQueuedBuildsForJobset createBaseJobset createJobsetWithOneInput evalSucceeds runBuild updateRepository);
our @EXPORT = qw(test_init hydra_setup nrBuildsForJobset queuedBuildsForJobset nrQueuedBuildsForJobset createBaseJobset createJobsetWithOneInput evalSucceeds runBuild updateRepository);
sub dbinit() {
my $pgsql = Test::PostgreSQL->new();
sub test_init() {
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";
open(my $fh, '>', $nixconf) or die "Could not open file '$nixconf' $!";
print $fh "sandbox = false\n";
close $fh;
$ENV{'NIX_STATE_DIR'} = "$dir/nix/var/nix";
$ENV{'NIX_MANIFESTS_DIR'} = "$dir/nix/var/nix/manifests";
$ENV{'NIX_STORE_DIR'} = "$dir/nix/store";
$ENV{'NIX_LOG_DIR'} = "$dir/nix/var/log/nix";
my $pgsql = Test::PostgreSQL->new(
extra_initdb_args => "--locale C.UTF-8"
);
$ENV{'HYDRA_DBI'} = $pgsql->dsn;
system("hydra-init") == 0 or die;
return $pgsql;
return ($dir, $pgsql);
}
sub captureStdoutStderr {