This commit is contained in:
Rob Vermaas 2011-03-17 11:55:39 +00:00
parent bf2f86d3c6
commit 597e7c04e1
2 changed files with 61 additions and 38 deletions

View file

@ -11,4 +11,48 @@ sub hydra_setup {
$db->resultset('Users')->create({ username => "root", emailaddress => 'root@email.com', password => '' });
}
sub nrBuildsForJobset {
my ($jobset) = @_;
return $jobset->builds->search({},{})->count ;
}
sub nrQueuedBuildsForJobset {
my ($jobset) = @_;
return $jobset->builds->search({},{ join => 'schedulingInfo' })->count ;
}
sub createBaseJobset {
my ($jobsetName, $nixexprpath) = @_;
my $project = $db->resultset('Projects')->update_or_create({name => "tests", displayname => "", owner => "root"});
my $jobset = $project->jobsets->create({name => $jobsetName, nixexprinput => "jobs", nixexprpath => $nixexprpath, emailoverride => ""});
my $jobsetinput;
my $jobsetinputals;
$jobsetinput = $jobset->jobsetinputs->create({name => "jobs", type => "path"});
$jobsetinputals = $jobsetinput->jobsetinputalts->create({altnr => 0, value => getcwd."/jobs"});
return $jobset;
}
sub createJobsetWithOneInput {
my ($jobsetName, $nixexprpath, $name, $type, $uri) = @_;
my $jobset = createBaseJobset($jobsetName, $nixexprpath);
my $jobsetinput;
my $jobsetinputals;
$jobsetinput = $jobset->jobsetinputs->create({name => $name, type => $type});
$jobsetinputals = $jobsetinput->jobsetinputalts->create({altnr => 1, value => $uri});
return $jobset;
}
sub evalSucceeds {
my ($jobset) = @_;
my $res = captureStdoutStderr(60, ("../src/script/hydra_evaluator.pl", $jobset->project->name, $jobset->name));
print STDERR "Evaluation errors for jobset ".$jobset->project->name.":".$jobset->name.": \n".$jobset->errormsg."\n" if $jobset->errormsg;
return $res;
}
1;

View file

@ -10,7 +10,7 @@ use Setup;
my $db = openHydraDB;
use Test::Simple tests => 14;
use Test::Simple tests => 16;
hydra_setup($db);
@ -20,49 +20,28 @@ my $stderr;
my $jobsBaseUri = "file://".getcwd;
my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});
my $jobset;
sub nrBuildsForJobset {
my ($project, $jobset) = @_;
return $db->resultset('Builds')->search({ project => $project, jobset => $jobset},{})->count ;
}
# Most basic test case, no parameters
$jobset = createBaseJobset("basic", "basic.nix");
sub createJobsetWithOneSCMInput {
my ($jobsetName, $nixexprpath, $type, $uri) = @_;
my $jobset = $project->jobsets->create({name => $jobsetName, nixexprinput => "jobs", nixexprpath => $nixexprpath, emailoverride => ""});
my $jobsetinput;
my $jobsetinputals;
$jobsetinput = $jobset->jobsetinputs->create({name => "jobs", type => "path"});
$jobsetinputals = $jobsetinput->jobsetinputalts->create({altnr => 0, value => getcwd."/jobs"});
$jobsetinput = $jobset->jobsetinputs->create({name => "src", type => $type});
$jobsetinputals = $jobsetinput->jobsetinputalts->create({altnr => 0, value => $uri});
return $jobset;
}
sub evalSucceeds {
my ($project, $jobset) = @_;
return captureStdoutStderr(60, ("../src/script/hydra_evaluator.pl", $project, $jobset));
}
my $jobset = $project->jobsets->create({name => "basic", nixexprinput => "jobs", nixexprpath => "basic.nix", emailoverride => ""});
my $jobsetinput = $jobset->jobsetinputs->create({name => "jobs", type => "path"});
my $jobsetinputals = $jobsetinput->jobsetinputalts->create({altnr => 0, value => getcwd."/jobs"});
($res, $stdout, $stderr) = captureStdoutStderr(60, ("../src/script/hydra_evaluator.pl", "tests", "basic"));
ok($res, "Evaluating jobs/basic.nix should exit with return code 0");
ok( nrBuildsForJobset("tests", "basic") == 3 , "Evaluating jobs/basic.nix should result in 3 builds");
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");
# 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");
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");
# Test scm inputs
my @scminputs = ("svn", "svn-checkout", "git", "bzr", "bzr-checkout", "hg");
foreach my $scm (@scminputs) {
$jobset = createJobsetWithOneSCMInput($scm, "$scm-input.nix", $scm, "$jobsBaseUri/$scm-repo");
ok(evalSucceeds("tests", $scm), "Evaluating jobs/$scm-input.nix should exit with return code 0.");
print STDERR "Evaluation errors for jobset tests:$scm: \n".$jobset->errormsg."\n" if $jobset->errormsg;
$jobset = createJobsetWithOneInput($scm, "$scm-input.nix", "src", $scm, "$jobsBaseUri/$scm-repo");
ok(nrBuildsForJobset("tests", $scm) == 1, "Evaluating jobs/$scm-input.nix should result in 1 build");
ok(evalSucceeds($jobset), "Evaluating jobs/$scm-input.nix should exit with return code 0.");
ok(nrQueuedBuildsForJobset($jobset) == 1, "Evaluating jobs/$scm-input.nix should result in 1 build in queue");
}