forked from NixOS/hydra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reimplement (named) constituent jobs (+globbing) based on nix-eval-jobs
Depends on nix-community/nix-eval-jobs#349 & NixOS#1421. Almost equivalent to NixOS#1425, but with a small change: when having e.g. an aggregate job with a glob that matches nothing, the jobset evaluation is failed now. This was the intended behavior before (hydra-eval-jobset fails hard if an aggregate is broken), the code-path was never reached however since the aggregate was never marked as broken in this case before.
- Loading branch information
Showing
12 changed files
with
374 additions
and
42 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
use strict; | ||
use warnings; | ||
use Setup; | ||
use Test2::V0; | ||
use Hydra::Helper::Exec; | ||
use Data::Dumper; | ||
|
||
my $ctx = test_context(); | ||
|
||
subtest "general glob testing" => sub { | ||
my $jobsetCtx = $ctx->makeJobset( | ||
expression => 'constituents-glob.nix', | ||
); | ||
my $jobset = $jobsetCtx->{"jobset"}; | ||
|
||
my ($res, $stdout, $stderr) = captureStdoutStderr(60, | ||
("hydra-eval-jobset", $jobsetCtx->{"project"}->name, $jobset->name) | ||
); | ||
is($res, 0, "hydra-eval-jobset exits zero"); | ||
|
||
my $builds = {}; | ||
for my $build ($jobset->builds) { | ||
$builds->{$build->job} = $build; | ||
} | ||
|
||
subtest "basic globbing works" => sub { | ||
ok(defined $builds->{"ok_aggregate"}, "'ok_aggregate' is part of the jobset evaluation"); | ||
my @constituents = $builds->{"ok_aggregate"}->constituents->all; | ||
is(2, scalar @constituents, "'ok_aggregate' has two constituents"); | ||
|
||
my @sortedConstituentNames = sort (map { $_->nixname } @constituents); | ||
|
||
is($sortedConstituentNames[0], "empty-dir-A", "first constituent of 'ok_aggregate' is 'empty-dir-A'"); | ||
is($sortedConstituentNames[1], "empty-dir-B", "second constituent of 'ok_aggregate' is 'empty-dir-B'"); | ||
}; | ||
|
||
subtest "transitivity is OK" => sub { | ||
ok(defined $builds->{"indirect_aggregate"}, "'indirect_aggregate' is part of the jobset evaluation"); | ||
my @constituents = $builds->{"indirect_aggregate"}->constituents->all; | ||
is(1, scalar @constituents, "'indirect_aggregate' has one constituent"); | ||
is($constituents[0]->nixname, "direct_aggregate", "'indirect_aggregate' has 'direct_aggregate' as single constituent"); | ||
}; | ||
}; | ||
|
||
subtest "* selects all except current aggregate" => sub { | ||
my $jobsetCtx = $ctx->makeJobset( | ||
expression => 'constituents-glob-all.nix', | ||
); | ||
my $jobset = $jobsetCtx->{"jobset"}; | ||
|
||
my ($res, $stdout, $stderr) = captureStdoutStderr(60, | ||
("hydra-eval-jobset", $jobsetCtx->{"project"}->name, $jobset->name) | ||
); | ||
|
||
subtest "no eval errors" => sub { | ||
ok(utf8::decode($stderr), "Stderr output is UTF8-clean"); | ||
ok( | ||
$stderr !~ "aggregate job ‘ok_aggregate’ has a constituent .* that doesn't correspond to a Hydra build", | ||
"Catchall wildcard must not select itself as constituent" | ||
); | ||
|
||
$jobset->discard_changes; # refresh from DB | ||
is( | ||
$jobset->errormsg, | ||
"", | ||
"eval-errors non-empty" | ||
); | ||
}; | ||
|
||
my $builds = {}; | ||
for my $build ($jobset->builds) { | ||
$builds->{$build->job} = $build; | ||
} | ||
|
||
subtest "two constituents" => sub { | ||
ok(defined $builds->{"ok_aggregate"}, "'ok_aggregate' is part of the jobset evaluation"); | ||
my @constituents = $builds->{"ok_aggregate"}->constituents->all; | ||
is(2, scalar @constituents, "'ok_aggregate' has two constituents"); | ||
|
||
my @sortedConstituentNames = sort (map { $_->nixname } @constituents); | ||
|
||
is($sortedConstituentNames[0], "empty-dir-A", "first constituent of 'ok_aggregate' is 'empty-dir-A'"); | ||
is($sortedConstituentNames[1], "empty-dir-B", "second constituent of 'ok_aggregate' is 'empty-dir-B'"); | ||
}; | ||
}; | ||
|
||
subtest "trivial cycle check" => sub { | ||
my $jobsetCtx = $ctx->makeJobset( | ||
expression => 'constituents-cycle.nix', | ||
); | ||
my $jobset = $jobsetCtx->{"jobset"}; | ||
|
||
my ($res, $stdout, $stderr) = captureStdoutStderr(60, | ||
("hydra-eval-jobset", $jobsetCtx->{"project"}->name, $jobset->name) | ||
); | ||
|
||
ok( | ||
$stderr =~ "Found dependency cycle between jobs 'indirect_aggregate' and 'ok_aggregate'", | ||
"Dependency cycle error is on stderr" | ||
); | ||
|
||
ok(utf8::decode($stderr), "Stderr output is UTF8-clean"); | ||
|
||
$jobset->discard_changes; # refresh from DB | ||
like( | ||
$jobset->errormsg, | ||
qr/Dependency cycle: indirect_aggregate <-> ok_aggregate/, | ||
"eval-errors non-empty" | ||
); | ||
|
||
is(0, $jobset->builds->count, "No builds should be scheduled"); | ||
}; | ||
|
||
subtest "cycle check with globbing" => sub { | ||
my $jobsetCtx = $ctx->makeJobset( | ||
expression => 'constituents-cycle-glob.nix', | ||
); | ||
my $jobset = $jobsetCtx->{"jobset"}; | ||
|
||
my ($res, $stdout, $stderr) = captureStdoutStderr(60, | ||
("hydra-eval-jobset", $jobsetCtx->{"project"}->name, $jobset->name) | ||
); | ||
|
||
ok(utf8::decode($stderr), "Stderr output is UTF8-clean"); | ||
|
||
$jobset->discard_changes; # refresh from DB | ||
like( | ||
$jobset->errormsg, | ||
qr/aggregate job ‘indirect_aggregate’ failed with the error: Dependency cycle: indirect_aggregate <-> packages.constituentA/, | ||
"packages.constituentA error missing" | ||
); | ||
|
||
# on this branch of Hydra, hydra-eval-jobset fails hard if an aggregate | ||
# job is broken. | ||
is(0, $jobset->builds->count, "Zero jobs are scheduled"); | ||
}; | ||
|
||
done_testing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
rec { | ||
path = "/nix/store/l9mg93sgx50y88p5rr6x1vib6j1rjsds-coreutils-9.1/bin"; | ||
|
||
mkDerivation = args: | ||
derivation ({ | ||
system = builtins.currentSystem; | ||
PATH = path; | ||
} // args); | ||
mkContentAddressedDerivation = args: mkDerivation ({ | ||
__contentAddressed = true; | ||
outputHashMode = "recursive"; | ||
outputHashAlgo = "sha256"; | ||
} // args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
with import ./config.nix; | ||
{ | ||
packages.constituentA = mkDerivation { | ||
name = "empty-dir-A"; | ||
builder = ./empty-dir-builder.sh; | ||
_hydraAggregate = true; | ||
_hydraGlobConstituents = true; | ||
constituents = [ "*_aggregate" ]; | ||
}; | ||
|
||
packages.constituentB = mkDerivation { | ||
name = "empty-dir-B"; | ||
builder = ./empty-dir-builder.sh; | ||
}; | ||
|
||
ok_aggregate = mkDerivation { | ||
name = "direct_aggregate"; | ||
_hydraAggregate = true; | ||
_hydraGlobConstituents = true; | ||
constituents = [ | ||
"packages.*" | ||
]; | ||
builder = ./empty-dir-builder.sh; | ||
}; | ||
|
||
indirect_aggregate = mkDerivation { | ||
name = "indirect_aggregate"; | ||
_hydraAggregate = true; | ||
constituents = [ | ||
"ok_aggregate" | ||
]; | ||
builder = ./empty-dir-builder.sh; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
with import ./config.nix; | ||
{ | ||
ok_aggregate = mkDerivation { | ||
name = "direct_aggregate"; | ||
_hydraAggregate = true; | ||
_hydraGlobConstituents = true; | ||
constituents = [ | ||
"indirect_aggregate" | ||
]; | ||
builder = ./empty-dir-builder.sh; | ||
}; | ||
|
||
indirect_aggregate = mkDerivation { | ||
name = "indirect_aggregate"; | ||
_hydraAggregate = true; | ||
constituents = [ | ||
"ok_aggregate" | ||
]; | ||
builder = ./empty-dir-builder.sh; | ||
}; | ||
} |
Oops, something went wrong.