SBKX3YH2EOCYY2IDACGOTXHJZSYSRHD5EC7FB6WGPKHLFYOF6SAAC
}
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;
}
sub createJobsetWithOneSCMInput {
my ($jobsetName, $nixexprpath, $type, $uri) = @_;
my $jobset = $project->jobsets->create({name => $jobsetName, nixexprinput => "jobs", nixexprpath => $nixexprpath, emailoverride => ""});
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");
$jobsetinput = $jobset->jobsetinputs->create({name => "jobs", type => "path"});
$jobsetinputals = $jobsetinput->jobsetinputalts->create({altnr => 0, value => getcwd."/jobs"});
# 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");
$jobsetinput = $jobset->jobsetinputs->create({name => "src", type => $type});
$jobsetinputals = $jobsetinput->jobsetinputalts->create({altnr => 0, value => $uri});
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");
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");
$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");