hydra/tests/evaluation-tests.pl

74 lines
3.5 KiB
Perl
Raw Normal View History

2011-03-16 13:18:12 +00:00
use strict;
use Hydra::Schema;
2012-03-13 12:18:40 +00:00
use Hydra::Model::DB;
2011-03-16 13:18:12 +00:00
use Hydra::Helper::AddBuilds;
use Cwd;
use Setup;
2012-03-13 12:18:40 +00:00
my $db = Hydra::Model::DB->new;
2011-03-16 13:18:12 +00:00
2012-04-15 01:17:35 +00:00
use Test::Simple tests => 48;
2011-03-16 13:18:12 +00:00
hydra_setup($db);
my $res;
my $stdout;
my $stderr;
2011-03-17 08:48:27 +00:00
my $jobsBaseUri = "file://".getcwd;
2011-03-16 13:18:12 +00:00
my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});
2011-03-17 11:55:39 +00:00
my $jobset;
2011-03-17 08:48:27 +00:00
2011-03-17 11:55:39 +00:00
# Most basic test case, no parameters
$jobset = createBaseJobset("basic", "basic.nix");
2011-03-17 08:48:27 +00:00
2011-03-17 11:55:39 +00:00
ok(evalSucceeds($jobset), "Evaluating jobs/basic.nix should exit with return code 0");
ok(nrQueuedBuildsForJobset($jobset) == 3 , "Evaluating jobs/basic.nix should result in 3 builds");
2011-03-17 08:48:27 +00:00
2011-03-17 13:25:27 +00:00
for my $build (queuedBuildsForJobset($jobset)) {
ok(runBuild($build), "Build '".$build->job->name."' from jobs/basic.nix should exit with code 0");
my $newbuild = $db->resultset('Builds')->find($build->id);
my $expected = $build->job->name eq "fails" ? 1 : 0;
2012-03-12 20:13:50 +00:00
ok($newbuild->finished == 1 && $newbuild->buildstatus == $expected, "Build '".$build->job->name."' from jobs/basic.nix should have buildstatus $expected");
2011-03-17 13:25:27 +00:00
}
2011-03-16 13:18:12 +00:00
2011-03-17 11:55:39 +00:00
# Test jobset with 2 jobs, one has parameter of succeeded build of the other
$jobset = createJobsetWithOneInput("build-output-as-input", "build-output-as-input.nix", "build1", "build", "build1");
2011-03-16 13:18:12 +00:00
2011-03-17 11:55:39 +00:00
ok(evalSucceeds($jobset), "Evaluating jobs/build-output-as-input.nix should exit with return code 0");
ok(nrQueuedBuildsForJobset($jobset) == 1 , "Evaluating jobs/build-output-as-input.nix for first time should result in 1 build in queue");
for my $build (queuedBuildsForJobset($jobset)) {
ok(runBuild($build), "Build '".$build->job->name."' from jobs/basic.nix should exit with code 0");
my $newbuild = $db->resultset('Builds')->find($build->id);
2012-03-12 20:13:50 +00:00
ok($newbuild->finished == 1 && $newbuild->buildstatus == 0, "Build '".$build->job->name."' from jobs/basic.nix should have buildstatus 0");
}
ok(evalSucceeds($jobset), "Evaluating jobs/build-output-as-input.nix for second time should exit with return code 0");
ok(nrQueuedBuildsForJobset($jobset) == 1 , "Evaluating jobs/build-output-as-input.nix for second time after building build1 should result in 1 build in queue");
for my $build (queuedBuildsForJobset($jobset)) {
ok(runBuild($build), "Build '".$build->job->name."' from jobs/basic.nix should exit with code 0");
my $newbuild = $db->resultset('Builds')->find($build->id);
2012-03-12 20:13:50 +00:00
ok($newbuild->finished == 1 && $newbuild->buildstatus == 0, "Build '".$build->job->name."' from jobs/basic.nix should have buildstatus 0");
}
2011-03-16 13:18:12 +00:00
2011-03-16 13:34:17 +00:00
2011-03-17 11:55:39 +00:00
# Test scm inputs
2011-03-17 08:48:27 +00:00
my @scminputs = ("svn", "svn-checkout", "git", "bzr", "bzr-checkout", "hg");
foreach my $scm (@scminputs) {
2011-03-17 11:55:39 +00:00
$jobset = createJobsetWithOneInput($scm, "$scm-input.nix", "src", $scm, "$jobsBaseUri/$scm-repo");
2011-03-17 10:29:01 +00:00
2012-04-15 01:17:35 +00:00
my $c = 1;
my $q = 1;
do {
# Verify that it can be fetched and queued.
ok(evalSucceeds($jobset), "$c Evaluating jobs/$scm-input.nix should exit with return code 0."); $c++;
ok(nrQueuedBuildsForJobset($jobset) == $q, "$c Evaluating jobs/$scm-input.nix should result in 1 build in queue"); $c++;
# Verify that it is deterministic and not queued again.
ok(evalSucceeds($jobset), "$c Evaluating jobs/$scm-input.nix should exit with return code 0."); $c++;
ok(nrQueuedBuildsForJobset($jobset) == $q, "$c Evaluating jobs/$scm-input.nix should result in $q build in queue"); $c++;
2011-03-16 13:18:12 +00:00
2012-04-15 01:17:35 +00:00
$q++;
} while(updateRepository($scm, getcwd . "/jobs/$scm-update.sh", getcwd . "/$scm-repo/"));
}