This makes the test faster (by removing it and replacing it with a
TestScmInput
module that exports the testScmInput
subroutine). Now,
all the input tests can be run in parallel.
Some of the tests/jobs/*-update.sh
scripts were "broken" (e.g. tests
failed for various reasons on my machine), so I fixed those up as well.
Co-authored-by: gustavderdrache <gustavderdrache@gmail.com>
F7WJVMRVVVHGPWTF67Y6YVZ6JNMH3PBK74VHQ24QRZD3RLUTYRSQC
IH26BRUJQD2PPZJHYRDGSGETB4FS26UMXD63ACSRD4GW3V7EITCAC
NYLYQIFHMCLACHQU3LGQCKTVIGBGOUBTGETNFWDKQCCZGDLMFO7AC
G7LMCJH5I2WJY5ZLDZHTBG537COFEUFYU7AQS6KZAME4ZFIHL3NQC
GBCPEGYCLFC5FUNAK2BV47G3EGQ26TPXSFCKVCY23QYET7A5A5YAC
G2ZB6464XGPBIMSZIPSB24EIXSCCGV4XWC3IWPS2CXYPDSUZSU5QC
ZTYKNDOLJNMR2WNAUVFJDIIY5J4ICINEP4AHHBNZA3DGVG5GL7EQC
HRBL4HYREOAGDMCUQQHTNL3BIKAUXDBIYUPX63SASSVGGXTOO3NAC
3RL7VFKEVVQBVKLKM7ZS3M67BOGGJ3OWPARHG64AOUTZTPPYCHLQC
HE3GX5IPS6XA7KLNP5WZY2YU27WQS663WSKAL5FHWBSJ5GMM633AC
ABB3BIS2X3MOXUJD5CUEODSJ3QCRZ4YDSNME2AHNCPG5OJ2F2I5QC
LZYXZOLKICHREHVGNCKPT4BLHUYBCFDOABGUYUWR3IXB44BLH3LAC
use strict;
use Cwd;
use Setup;
(my $datadir, my $pgsql) = test_init();
require Hydra::Schema;
require Hydra::Model::DB;
use Test2::V0;
my $db = Hydra::Model::DB->new;
hydra_setup($db);
my $testdir = getcwd;
my $scratchdir = "$datadir/scratch";
mkdir $scratchdir;
my $jobsBaseUri = "file://".$scratchdir;
# Test scm inputs
my @scminputs = (
{
name => "svn",
nixexpr => "svn-input.nix",
type => "svn",
uri => "$jobsBaseUri/svn-repo",
update => $testdir . "/jobs/svn-update.sh"
},
{
name => "svn-checkout",
nixexpr => "svn-checkout-input.nix",
type => "svn-checkout",
uri => "$jobsBaseUri/svn-checkout-repo",
update => $testdir . "/jobs/svn-checkout-update.sh"
},
{
name => "git",
nixexpr => "git-input.nix",
type => "git",
uri => "$jobsBaseUri/git-repo",
update => $testdir . "/jobs/git-update.sh"
},
{
name => "git-rev",
nixexpr => "git-rev-input.nix",
type => "git",
uri => "$jobsBaseUri/git-repo 7f60df502b96fd54bbfa64dd94b56d936a407701",
update => $testdir . "/jobs/git-rev-update.sh"
},
{
name => "deepgit",
nixexpr => "deepgit-input.nix",
type => "git",
uri => "$jobsBaseUri/git-repo master 1",
update => $testdir . "/jobs/git-update.sh"
},
{
name => "bzr",
nixexpr => "bzr-input.nix",
type => "bzr",
uri => "$jobsBaseUri/bzr-repo",
update => $testdir . "/jobs/bzr-update.sh"
},
{
name => "bzr-checkout",
nixexpr => "bzr-checkout-input.nix",
type => "bzr-checkout",
uri => "$jobsBaseUri/bzr-checkout-repo",
update => $testdir . "/jobs/bzr-checkout-update.sh"
},
{
name => "hg",
nixexpr => "hg-input.nix",
type => "hg",
uri => "$jobsBaseUri/hg-repo",
update => $testdir . "/jobs/hg-update.sh"
},
{
name => "darcs",
nixexpr => "darcs-input.nix",
type => "darcs",
uri => "$jobsBaseUri/darcs-repo",
update => $testdir . "/jobs/darcs-update.sh"
}
);
foreach my $scm ( @scminputs ) {
my $scmName = $scm->{"name"};
subtest "With the SCM input named $scmName" => sub {
my $nixexpr = $scm->{"nixexpr"};
my $type = $scm->{"type"};
my $uri = $scm->{"uri"};
my $update = $scm->{"update"};
my $jobset = createJobsetWithOneInput($scmName, $nixexpr, "src", $type, $uri);
my $state = 0;
my $q = 0;
my ($loop, $updated) = updateRepository($scmName, $update, $scratchdir);
while($loop) {
subtest "Mutation number $state" => sub {
# Verify that it can be fetched and possibly queued.
ok(evalSucceeds($jobset), "Evaluating nix-expression.");
# Verify that the evaluation has queued a new job and evaluate again to ...
if ($updated) {
$q++;
is(nrQueuedBuildsForJobset($jobset), $q, "Expect $q jobs in the queue.");
ok(evalSucceeds($jobset), "Evaluating nix-expression again.");
}
# ... check that it is deterministic and not queued again.
is(nrQueuedBuildsForJobset($jobset), $q, "Expect deterministic evaluation.");
$state++;
($loop, $updated) = updateRepository($scmName, $update, $scratchdir);
};
}
};
}
done_testing;
use strict;
use Cwd;
use Setup;
use TestScmInput;
(my $datadir, my $pgsql) = test_init();
require Hydra::Schema;
require Hydra::Model::DB;
use Test2::V0;
my $db = Hydra::Model::DB->new;
hydra_setup($db);
# Tests the creation of a Hydra jobset using a bzr checkout as input.
testScmInput(
type => 'bzr-checkout',
expr => 'bzr-checkout-input.nix',
uri => 'bzr-checkout-repo',
update => 'jobs/bzr-checkout-update.sh',
# directories
datadir => $datadir,
testdir => getcwd,
);
done_testing;
use strict;
use Cwd;
use Setup;
use TestScmInput;
(my $datadir, my $pgsql) = test_init();
require Hydra::Schema;
require Hydra::Model::DB;
use Test2::V0;
my $db = Hydra::Model::DB->new;
hydra_setup($db);
# Tests the creation of a Hydra jobset using a bzr repo as input.
testScmInput(
type => 'bzr',
expr => 'bzr-input.nix',
uri => 'bzr-repo',
update => 'jobs/bzr-update.sh',
# directories
datadir => $datadir,
testdir => getcwd,
);
done_testing;
use strict;
use Cwd;
use Setup;
use TestScmInput;
(my $datadir, my $pgsql) = test_init();
require Hydra::Schema;
require Hydra::Model::DB;
use Test2::V0;
my $db = Hydra::Model::DB->new;
hydra_setup($db);
# Tests the creation of a Hydra jobset using a darcs repo as input.
testScmInput(
type => 'darcs',
expr => 'darcs-input.nix',
uri => 'darcs-repo',
update => 'jobs/darcs-update.sh',
# directories
datadir => $datadir,
testdir => getcwd,
);
done_testing;
use strict;
use Cwd;
use Setup;
use TestScmInput;
(my $datadir, my $pgsql) = test_init();
require Hydra::Schema;
require Hydra::Model::DB;
use Test2::V0;
my $db = Hydra::Model::DB->new;
hydra_setup($db);
# Tests the creation of a Hydra jobset using a deep git clone as input.
testScmInput(
type => 'git',
name => 'deepgit',
expr => 'deepgit-input.nix',
uri => 'git-repo master 1',
update => 'jobs/git-update.sh',
# directories
datadir => $datadir,
testdir => getcwd,
);
done_testing;
use strict;
use Cwd;
use Setup;
use TestScmInput;
(my $datadir, my $pgsql) = test_init();
require Hydra::Schema;
require Hydra::Model::DB;
use Test2::V0;
my $db = Hydra::Model::DB->new;
hydra_setup($db);
# Tests the creation of a Hydra jobset using a git revision as input.
testScmInput(
type => 'git',
name => 'git-rev',
expr => 'git-rev-input.nix',
uri => 'git-repo 7f60df502b96fd54bbfa64dd94b56d936a407701',
update => 'jobs/git-rev-update.sh',
# directories
datadir => $datadir,
testdir => getcwd,
);
done_testing;
use strict;
use Cwd;
use Setup;
use TestScmInput;
(my $datadir, my $pgsql) = test_init();
require Hydra::Schema;
require Hydra::Model::DB;
use Test2::V0;
my $db = Hydra::Model::DB->new;
hydra_setup($db);
# Tests the creation of a Hydra jobset using a git repo as input.
testScmInput(
type => 'git',
expr => 'git-input.nix',
uri => 'git-repo',
update => 'jobs/git-update.sh',
# directories
datadir => $datadir,
testdir => getcwd,
);
done_testing;
use strict;
use Cwd;
use Setup;
use TestScmInput;
(my $datadir, my $pgsql) = test_init();
require Hydra::Schema;
require Hydra::Model::DB;
use Test2::V0;
my $db = Hydra::Model::DB->new;
hydra_setup($db);
# Tests the creation of a Hydra jobset using a hg repo as input.
testScmInput(
type => 'hg',
expr => 'hg-input.nix',
uri => 'hg-repo',
update => 'jobs/hg-update.sh',
# directories
datadir => $datadir,
testdir => getcwd,
);
done_testing;
use strict;
use Cwd;
use Setup;
use TestScmInput;
(my $datadir, my $pgsql) = test_init();
require Hydra::Schema;
require Hydra::Model::DB;
use Test2::V0;
my $db = Hydra::Model::DB->new;
hydra_setup($db);
# Tests the creation of a Hydra jobset using a svn checkout as input.
testScmInput(
type => 'svn-checkout',
expr => 'svn-checkout-input.nix',
uri => 'svn-checkout-repo',
update => 'jobs/svn-checkout-update.sh',
# directories
datadir => $datadir,
testdir => getcwd,
);
done_testing;
use strict;
use Cwd;
use Setup;
use TestScmInput;
(my $datadir, my $pgsql) = test_init();
require Hydra::Schema;
require Hydra::Model::DB;
use Test2::V0;
my $db = Hydra::Model::DB->new;
hydra_setup($db);
# Tests the creation of a Hydra jobset using a svn repo as input.
testScmInput(
type => 'svn',
expr => 'svn-input.nix',
uri => 'svn-repo',
update => 'jobs/svn-update.sh',
# directories
datadir => $datadir,
testdir => getcwd,
);
done_testing;
package TestScmInput;
use warnings;
use strict;
use Exporter;
use Test2::V0;
use Setup;
our @ISA = qw(Exporter);
our @EXPORT = qw(testScmInput);
# Generic test for the various SCM types Hydra supports.
#
# Takes input in the form of:
#
# (
# type => "input type",
# name => "jobset name", # defaults to the input's type
# uri => "uri",
# update => "script for updating the input",
# datadir => "data dir", # returned from `test_init()` subroutine
# testdir => "the hydra tests directory", # usually just `getcwd`
# )
#
# and runs a test that constructs a jobset from the specified input.
sub testScmInput {
# Collect named args, dying if a required arg is missing
my %args = @_;
my $type = $args{type} // die "required arg 'type' missing";
my $expr = $args{expr} // die "required arg 'expr' missing";
# $name is optional and defaults to $type
my $name = $args{name} // $type;
# Get directories
my $testdir = $args{testdir} // die "required arg 'testdir' missing";
my $datadir = $args{datadir} // die "required arg 'datadir' missing";
my $update = $args{update} // die "required arg 'update' missing";
$update = "$testdir/$update";
# Create scratch locations
my $scratchdir = "$datadir/scratch";
mkdir $scratchdir or die "mkdir($scratchdir): $!\n";
# $uri and $update are constructed from the directories
my $uri = $args{uri} // die "required arg 'uri' missing";
$uri = "file://$scratchdir/$uri";
subtest "With the SCM input named $name" => sub {
my $jobset = createJobsetWithOneInput($name, $expr, 'src', $type, $uri);
my ($mutations, $queueSize) = (0, 0);
my ($loop, $updated) = updateRepository($name, $update, $scratchdir);
while ($loop) {
subtest "Mutation number $mutations" => sub {
ok(evalSucceeds($jobset), "Evaluating nix-expression.");
if ($updated) {
$queueSize++;
is(nrQueuedBuildsForJobset($jobset), $queueSize, "Expect $queueSize jobs in the queue.");
ok(evalSucceeds($jobset), "Evaluating nix-expression again.");
}
is(nrQueuedBuildsForJobset($jobset), $queueSize, "Expect deterministic evaluation.");
$mutations++;
($loop, $updated) = updateRepository($name, $update, $scratchdir);
};
}
};
}