Merge pull request #882 from cole-h/split-inputtype-test

tests/input-types: split out scminputs into individual tests
This commit is contained in:
Graham Christensen 2021-03-04 17:13:22 -05:00 committed by GitHub
commit 26cfe624d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 342 additions and 122 deletions

1
.gitignore vendored
View file

@ -29,6 +29,7 @@ Makefile.in
/tests/.git*
/tests/.hg*
/tests/nix
/tests/data
/inst
hydra-config.h
hydra-config.h.in

View file

@ -1,122 +0,0 @@
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;

View file

@ -0,0 +1,28 @@
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;

28
tests/input-types/bzr.t Normal file
View file

@ -0,0 +1,28 @@
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;

28
tests/input-types/darcs.t Normal file
View file

@ -0,0 +1,28 @@
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;

View file

@ -0,0 +1,29 @@
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;

View file

@ -0,0 +1,29 @@
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;

28
tests/input-types/git.t Normal file
View file

@ -0,0 +1,28 @@
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;

28
tests/input-types/hg.t Normal file
View file

@ -0,0 +1,28 @@
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;

View file

@ -0,0 +1,28 @@
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;

28
tests/input-types/svn.t Normal file
View file

@ -0,0 +1,28 @@
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;

View file

@ -9,8 +9,14 @@ else
state=0;
fi
export BZR_HOME; # Set by the Makefile
case $state in
(0) echo "::Create repo. -- continue -- updated::"
bzr init bzr-repo
bzr whoami "build <build@invalid.org>" -d bzr-repo
touch bzr-repo/bzr-file
bzr add bzr-repo/bzr-file
bzr commit -m "add bzr-file" bzr-repo/bzr-file
ln -s bzr-repo bzr-checkout-repo
;;
(*) echo "::End. -- stop -- nothing::" ;;

View file

@ -3,6 +3,7 @@ set -e
repo=git-repo
export HOME=$(pwd)
export XDG_CONFIG_HOME=$(pwd)/.config
STATE_FILE=$(pwd)/.git-rev-state
if test -e $STATE_FILE; then
state=1

View file

@ -4,6 +4,7 @@ set -e
repo=git-repo
export HOME=$(pwd)
export XDG_CONFIG_HOME=$(pwd)/.config
STATE_FILE=$(pwd)/.git-state
if test -e $STATE_FILE; then
state=$(cat $STATE_FILE)

View file

@ -11,6 +11,11 @@ fi
case $state in
(0) echo "::Create repo. -- continue -- updated::"
svnadmin create svn-repo
svn co file://$PWD/$repo svn-checkout
touch svn-checkout/svn-file
svn add svn-checkout/svn-file
svn commit -m "add svn file" svn-checkout/svn-file
ln -s svn-repo svn-checkout-repo
;;
(*) echo "::End. -- stop -- nothing::" ;;

74
tests/lib/TestScmInput.pm Normal file
View file

@ -0,0 +1,74 @@
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);
};
}
};
}