Skip to content

Commit

Permalink
Bring back constituents
Browse files Browse the repository at this point in the history
This partially reverts commit 370a4bf.

(cherry picked from commit cdfc5c81e8037d3e4818a3e459d0804b2c157ea9)
  • Loading branch information
Ma27 authored and Ericson2314 committed Dec 10, 2024
1 parent 1888a64 commit 59da56a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
23 changes: 14 additions & 9 deletions src/script/hydra-eval-jobset
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ sub evalJobs {
push @cmd, ("--gc-roots-dir", getGCRootsDir);
push @cmd, ("--max-jobs", 1);
push @cmd, "--meta";
push @cmd, "--constituents";
push @cmd, "--force-recurse";
push @cmd, ("--option", "allow-import-from-derivation", "false") if $config->{allow_import_from_derivation} // "true" ne "true";

Expand Down Expand Up @@ -776,6 +777,8 @@ sub checkJobsetWrapped {
, nixexprpath => $jobset->nixexprpath
});

my @jobsWithConstituents;

while (defined(my $job = $jobsIter->())) {
if ($jobsetsJobset) {
die "The .jobsets jobset must only have a single job named 'jobsets'"
Expand All @@ -788,6 +791,10 @@ sub checkJobsetWrapped {

checkBuild($db, $jobset, $ev, $inputInfo, $job, \%buildMap, $prevEval, $jobOutPathMap, $plugins)
unless defined $job->{error};

if (defined $job->{constituents}) {
push @jobsWithConstituents, $job;
}
}

# Have any builds been added or removed since last time?
Expand Down Expand Up @@ -819,28 +826,26 @@ sub checkJobsetWrapped {
my $x = $buildMap{$id};
my $y = $drvPathToId{$x->{drvPath}};
if (defined $y) {
next if length $x->{jobName} > length $y->{jobName};
next if length $x->{jobName} == length $y->{jobName} && $x->{jobName} ge $y->{jobName};
next if length $x->{attr} > length $y->{attr};
next if length $x->{attr} == length $y->{attr} && $x->{attr} ge $y->{attr};
}
$drvPathToId{$x->{drvPath}} = $x;
}

# XXX: dead code with nix-eval-jobs. To be removed.
foreach my $job (values @jobs) {
next unless $job->{constituents};

foreach my $job (values @jobsWithConstituents) {
next unless defined $job->{constituents};
if (defined $job->{error}) {
die "aggregate job ‘$job->{jobName}’ failed with the error: $job->{error}\n";
die "aggregate job ‘$job->{attr}’ failed with the error: $job->{error}\n";
}

my $x = $drvPathToId{$job->{drvPath}} or
die "aggregate job ‘$job->{jobName}’ has no corresponding build record.\n";
die "aggregate job ‘$job->{attr}’ has no corresponding build record.\n";
foreach my $drvPath (@{$job->{constituents}}) {
my $constituent = $drvPathToId{$drvPath};
if (defined $constituent) {
$db->resultset('AggregateConstituents')->update_or_create({aggregate => $x->{id}, constituent => $constituent->{id}});
} else {
warn "aggregate job ‘$job->{jobName}’ has a constituent ‘$drvPath’ that doesn't correspond to a Hydra build\n";
warn "aggregate job ‘$job->{attr}’ has a constituent ‘$drvPath’ that doesn't correspond to a Hydra build\n";
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions t/evaluator/evaluate-constituents-broken.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ isnt($res, 0, "hydra-eval-jobset exits non-zero");
ok(utf8::decode($stderr), "Stderr output is UTF8-clean");
like(
$stderr,
qr/aggregate job ‘mixed_aggregate’ failed with the error: constituentA: does not exist/,
qr/aggregate job ‘mixed_aggregate’ failed with the error: "constituentA": does not exist/,
"The stderr record includes a relevant error message"
);

$jobset->discard_changes; # refresh from DB
$jobset->discard_changes({ '+columns' => {'errormsg' => 'errormsg'} }); # refresh from DB
like(
$jobset->errormsg,
qr/aggregate job ‘mixed_aggregate’ failed with the error: constituentA: does not exist/,
qr/aggregate job ‘mixed_aggregate’ failed with the error: "constituentA": does not exist/,
"The jobset records a relevant error message"
);

Expand Down
4 changes: 2 additions & 2 deletions t/queue-runner/constituents.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ is(nrQueuedBuildsForJobset($jobset), 0, "Evaluating jobs/broken-constituent.nix

like(
$jobset->errormsg,
qr/^does-not-exist: does not exist$/m,
qr/^"does-not-exist": does not exist$/m,
"Evaluating jobs/broken-constituent.nix should log an error for does-not-exist");
like(
$jobset->errormsg,
qr/^does-not-evaluate: error: assertion 'false' failed$/m,
qr/^"does-not-evaluate": "error: assertion 'false' failed/m,
"Evaluating jobs/broken-constituent.nix should log an error for does-not-evaluate");

done_testing;

0 comments on commit 59da56a

Please sign in to comment.