tests: add jobsdir and testdir to ctx hash

This allows us to calculate those directories only once, and just pass
them around as necessary.
This commit is contained in:
Cole Helbling 2021-03-04 17:22:37 -08:00
parent f08d0be1bd
commit 9a3af13c51
No known key found for this signature in database
GPG key ID: B37E0F2371016A4C
15 changed files with 53 additions and 40 deletions

View file

@ -15,7 +15,7 @@ hydra_setup($db);
# Test build products # Test build products
my $jobset = createBaseJobset("build-products", "build-products.nix"); my $jobset = createBaseJobset("build-products", "build-products.nix", $ctx{jobsdir});
ok(evalSucceeds($jobset), "Evaluating jobs/build-products.nix should exit with return code 0"); ok(evalSucceeds($jobset), "Evaluating jobs/build-products.nix should exit with return code 0");
is(nrQueuedBuildsForJobset($jobset), 2, "Evaluating jobs/build-products.nix should result in 2 builds"); is(nrQueuedBuildsForJobset($jobset), 2, "Evaluating jobs/build-products.nix should result in 2 builds");

View file

@ -16,7 +16,7 @@ hydra_setup($db);
my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"}); my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});
# Most basic test case, no parameters # Most basic test case, no parameters
my $jobset = createBaseJobset("basic", "basic.nix"); my $jobset = createBaseJobset("basic", "basic.nix", $ctx{jobsdir});
ok(evalSucceeds($jobset), "Evaluating jobs/basic.nix should exit with return code 0"); ok(evalSucceeds($jobset), "Evaluating jobs/basic.nix should exit with return code 0");
is(nrQueuedBuildsForJobset($jobset), 3, "Evaluating jobs/basic.nix should result in 3 builds"); is(nrQueuedBuildsForJobset($jobset), 3, "Evaluating jobs/basic.nix should result in 3 builds");

View file

@ -13,7 +13,7 @@ my $db = Hydra::Model::DB->new;
hydra_setup($db); hydra_setup($db);
# Test jobset with 2 jobs, one has parameter of succeeded build of the other # Test jobset with 2 jobs, one has parameter of succeeded build of the other
my $jobset = createJobsetWithOneInput("build-output-as-input", "build-output-as-input.nix", "build1", "build", "build1"); my $jobset = createJobsetWithOneInput("build-output-as-input", "build-output-as-input.nix", "build1", "build", "build1", $ctx{jobsdir});
ok(evalSucceeds($jobset), "Evaluating jobs/build-output-as-input.nix should exit with return code 0"); ok(evalSucceeds($jobset), "Evaluating jobs/build-output-as-input.nix should exit with return code 0");
is(nrQueuedBuildsForJobset($jobset), 1 , "Evaluation should result in 1 build in queue"); is(nrQueuedBuildsForJobset($jobset), 1 , "Evaluation should result in 1 build in queue");

View file

@ -3,7 +3,7 @@ use Cwd;
use Setup; use Setup;
use TestScmInput; use TestScmInput;
(my $datadir, my $pgsql) = test_init(); my %ctx = test_init();
require Hydra::Schema; require Hydra::Schema;
require Hydra::Model::DB; require Hydra::Model::DB;
@ -21,8 +21,9 @@ testScmInput(
update => 'jobs/bzr-checkout-update.sh', update => 'jobs/bzr-checkout-update.sh',
# directories # directories
datadir => $datadir, datadir => $ctx{tmpdir},
testdir => getcwd, testdir => $ctx{testdir},
jobsdir => $ctx{jobsdir},
); );
done_testing; done_testing;

View file

@ -3,7 +3,7 @@ use Cwd;
use Setup; use Setup;
use TestScmInput; use TestScmInput;
(my $datadir, my $pgsql) = test_init(); my %ctx = test_init();
require Hydra::Schema; require Hydra::Schema;
require Hydra::Model::DB; require Hydra::Model::DB;
@ -21,8 +21,9 @@ testScmInput(
update => 'jobs/bzr-update.sh', update => 'jobs/bzr-update.sh',
# directories # directories
datadir => $datadir, datadir => $ctx{tmpdir},
testdir => getcwd, testdir => $ctx{testdir},
jobsdir => $ctx{jobsdir},
); );
done_testing; done_testing;

View file

@ -3,7 +3,7 @@ use Cwd;
use Setup; use Setup;
use TestScmInput; use TestScmInput;
(my $datadir, my $pgsql) = test_init(); my %ctx = test_init();
require Hydra::Schema; require Hydra::Schema;
require Hydra::Model::DB; require Hydra::Model::DB;
@ -21,8 +21,9 @@ testScmInput(
update => 'jobs/darcs-update.sh', update => 'jobs/darcs-update.sh',
# directories # directories
datadir => $datadir, datadir => $ctx{tmpdir},
testdir => getcwd, testdir => $ctx{testdir},
jobsdir => $ctx{jobsdir},
); );
done_testing; done_testing;

View file

@ -3,7 +3,7 @@ use Cwd;
use Setup; use Setup;
use TestScmInput; use TestScmInput;
(my $datadir, my $pgsql) = test_init(); my %ctx = test_init();
require Hydra::Schema; require Hydra::Schema;
require Hydra::Model::DB; require Hydra::Model::DB;
@ -22,8 +22,9 @@ testScmInput(
update => 'jobs/git-update.sh', update => 'jobs/git-update.sh',
# directories # directories
datadir => $datadir, datadir => $ctx{tmpdir},
testdir => getcwd, testdir => $ctx{testdir},
jobsdir => $ctx{jobsdir},
); );
done_testing; done_testing;

View file

@ -3,7 +3,7 @@ use Cwd;
use Setup; use Setup;
use TestScmInput; use TestScmInput;
(my $datadir, my $pgsql) = test_init(); my %ctx = test_init();
require Hydra::Schema; require Hydra::Schema;
require Hydra::Model::DB; require Hydra::Model::DB;
@ -22,8 +22,9 @@ testScmInput(
update => 'jobs/git-rev-update.sh', update => 'jobs/git-rev-update.sh',
# directories # directories
datadir => $datadir, datadir => $ctx{tmpdir},
testdir => getcwd, testdir => $ctx{testdir},
jobsdir => $ctx{jobsdir},
); );
done_testing; done_testing;

View file

@ -3,7 +3,7 @@ use Cwd;
use Setup; use Setup;
use TestScmInput; use TestScmInput;
(my $datadir, my $pgsql) = test_init(); my %ctx = test_init();
require Hydra::Schema; require Hydra::Schema;
require Hydra::Model::DB; require Hydra::Model::DB;
@ -21,8 +21,9 @@ testScmInput(
update => 'jobs/git-update.sh', update => 'jobs/git-update.sh',
# directories # directories
datadir => $datadir, datadir => $ctx{tmpdir},
testdir => getcwd, testdir => $ctx{testdir},
jobsdir => $ctx{jobsdir},
); );
done_testing; done_testing;

View file

@ -3,7 +3,7 @@ use Cwd;
use Setup; use Setup;
use TestScmInput; use TestScmInput;
(my $datadir, my $pgsql) = test_init(); my %ctx = test_init();
require Hydra::Schema; require Hydra::Schema;
require Hydra::Model::DB; require Hydra::Model::DB;
@ -21,8 +21,9 @@ testScmInput(
update => 'jobs/hg-update.sh', update => 'jobs/hg-update.sh',
# directories # directories
datadir => $datadir, datadir => $ctx{tmpdir},
testdir => getcwd, testdir => $ctx{testdir},
jobsdir => $ctx{jobsdir},
); );
done_testing; done_testing;

View file

@ -3,7 +3,7 @@ use Cwd;
use Setup; use Setup;
use TestScmInput; use TestScmInput;
(my $datadir, my $pgsql) = test_init(); my %ctx = test_init();
require Hydra::Schema; require Hydra::Schema;
require Hydra::Model::DB; require Hydra::Model::DB;
@ -21,8 +21,9 @@ testScmInput(
update => 'jobs/svn-checkout-update.sh', update => 'jobs/svn-checkout-update.sh',
# directories # directories
datadir => $datadir, datadir => $ctx{tmpdir},
testdir => getcwd, testdir => $ctx{testdir},
jobsdir => $ctx{jobsdir},
); );
done_testing; done_testing;

View file

@ -3,7 +3,7 @@ use Cwd;
use Setup; use Setup;
use TestScmInput; use TestScmInput;
(my $datadir, my $pgsql) = test_init(); my %ctx = test_init();
require Hydra::Schema; require Hydra::Schema;
require Hydra::Model::DB; require Hydra::Model::DB;
@ -21,8 +21,9 @@ testScmInput(
update => 'jobs/svn-update.sh', update => 'jobs/svn-update.sh',
# directories # directories
datadir => $datadir, datadir => $ctx{tmpdir},
testdir => getcwd, testdir => $ctx{testdir},
jobsdir => $ctx{jobsdir},
); );
done_testing; done_testing;

View file

@ -5,7 +5,8 @@ use Exporter;
use Test::PostgreSQL; use Test::PostgreSQL;
use File::Temp; use File::Temp;
use File::Path qw(make_path); use File::Path qw(make_path);
use Cwd; use File::Basename;
use Cwd qw(abs_path getcwd);
our @ISA = qw(Exporter); 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);
@ -63,8 +64,10 @@ sub test_init {
$ENV{'HYDRA_DBI'} = $pgsql->dsn; $ENV{'HYDRA_DBI'} = $pgsql->dsn;
system("hydra-init") == 0 or die; system("hydra-init") == 0 or die;
return ( return (
db => $pgsql,
tmpdir => $dir, tmpdir => $dir,
db => $pgsql testdir => abs_path(dirname(__FILE__) . "/.."),
jobsdir => abs_path(dirname(__FILE__) . "/../jobs")
); );
} }
@ -98,7 +101,7 @@ sub nrQueuedBuildsForJobset {
} }
sub createBaseJobset { sub createBaseJobset {
my ($jobsetName, $nixexprpath) = @_; my ($jobsetName, $nixexprpath, $jobspath) = @_;
my $db = Hydra::Model::DB->new; my $db = Hydra::Model::DB->new;
my $project = $db->resultset('Projects')->update_or_create({name => "tests", displayname => "", owner => "root"}); my $project = $db->resultset('Projects')->update_or_create({name => "tests", displayname => "", owner => "root"});
@ -108,14 +111,14 @@ sub createBaseJobset {
my $jobsetinputals; my $jobsetinputals;
$jobsetinput = $jobset->jobsetinputs->create({name => "jobs", type => "path"}); $jobsetinput = $jobset->jobsetinputs->create({name => "jobs", type => "path"});
$jobsetinputals = $jobsetinput->jobsetinputalts->create({altnr => 0, value => getcwd."/jobs"}); $jobsetinputals = $jobsetinput->jobsetinputalts->create({altnr => 0, value => $jobspath});
return $jobset; return $jobset;
} }
sub createJobsetWithOneInput { sub createJobsetWithOneInput {
my ($jobsetName, $nixexprpath, $name, $type, $uri) = @_; my ($jobsetName, $nixexprpath, $name, $type, $uri, $jobspath) = @_;
my $jobset = createBaseJobset($jobsetName, $nixexprpath); my $jobset = createBaseJobset($jobsetName, $nixexprpath, $jobspath);
my $jobsetinput; my $jobsetinput;
my $jobsetinputals; my $jobsetinputals;

View file

@ -36,6 +36,7 @@ sub testScmInput {
# Get directories # Get directories
my $testdir = $args{testdir} // die "required arg 'testdir' missing"; my $testdir = $args{testdir} // die "required arg 'testdir' missing";
my $datadir = $args{datadir} // die "required arg 'datadir' missing"; my $datadir = $args{datadir} // die "required arg 'datadir' missing";
my $jobsdir = $args{jobsdir} // die "required arg 'jobsdir' missing";
my $update = $args{update} // die "required arg 'update' missing"; my $update = $args{update} // die "required arg 'update' missing";
$update = "$testdir/$update"; $update = "$testdir/$update";
@ -49,7 +50,7 @@ sub testScmInput {
$uri = "file://$scratchdir/$uri"; $uri = "file://$scratchdir/$uri";
subtest "With the SCM input named $name" => sub { subtest "With the SCM input named $name" => sub {
my $jobset = createJobsetWithOneInput($name, $expr, 'src', $type, $uri); my $jobset = createJobsetWithOneInput($name, $expr, 'src', $type, $uri, $jobsdir);
my ($mutations, $queueSize) = (0, 0); my ($mutations, $queueSize) = (0, 0);

View file

@ -23,7 +23,7 @@ hydra_setup($db);
my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"}); my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});
# Most basic test case, no parameters # Most basic test case, no parameters
my $jobset = createBaseJobset("basic", "runcommand.nix"); my $jobset = createBaseJobset("basic", "runcommand.nix", $ctx{jobsdir});
ok(evalSucceeds($jobset), "Evaluating jobs/runcommand.nix should exit with return code 0"); ok(evalSucceeds($jobset), "Evaluating jobs/runcommand.nix should exit with return code 0");
is(nrQueuedBuildsForJobset($jobset), 1, "Evaluating jobs/runcommand.nix should result in 1 build1"); is(nrQueuedBuildsForJobset($jobset), 1, "Evaluating jobs/runcommand.nix should result in 1 build1");