|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | +use Setup; |
| 4 | +use Test2::V0; |
| 5 | +use Hydra::Helper::Exec; |
| 6 | +use Data::Dumper; |
| 7 | + |
| 8 | +my $ctx = test_context(); |
| 9 | + |
| 10 | +subtest "general glob testing" => sub { |
| 11 | + my $jobsetCtx = $ctx->makeJobset( |
| 12 | + expression => 'constituents-glob.nix', |
| 13 | + ); |
| 14 | + my $jobset = $jobsetCtx->{"jobset"}; |
| 15 | + |
| 16 | + my ($res, $stdout, $stderr) = captureStdoutStderr(60, |
| 17 | + ("hydra-eval-jobset", $jobsetCtx->{"project"}->name, $jobset->name) |
| 18 | + ); |
| 19 | + is($res, 0, "hydra-eval-jobset exits zero"); |
| 20 | + |
| 21 | + my $builds = {}; |
| 22 | + for my $build ($jobset->builds) { |
| 23 | + $builds->{$build->job} = $build; |
| 24 | + } |
| 25 | + |
| 26 | + subtest "basic globbing works" => sub { |
| 27 | + ok(defined $builds->{"ok_aggregate"}, "'ok_aggregate' is part of the jobset evaluation"); |
| 28 | + my @constituents = $builds->{"ok_aggregate"}->constituents->all; |
| 29 | + is(2, scalar @constituents, "'ok_aggregate' has two constituents"); |
| 30 | + |
| 31 | + my @sortedConstituentNames = sort (map { $_->nixname } @constituents); |
| 32 | + |
| 33 | + is($sortedConstituentNames[0], "empty-dir-A", "first constituent of 'ok_aggregate' is 'empty-dir-A'"); |
| 34 | + is($sortedConstituentNames[1], "empty-dir-B", "second constituent of 'ok_aggregate' is 'empty-dir-B'"); |
| 35 | + }; |
| 36 | + |
| 37 | + subtest "transitivity is OK" => sub { |
| 38 | + ok(defined $builds->{"indirect_aggregate"}, "'indirect_aggregate' is part of the jobset evaluation"); |
| 39 | + my @constituents = $builds->{"indirect_aggregate"}->constituents->all; |
| 40 | + is(1, scalar @constituents, "'indirect_aggregate' has one constituent"); |
| 41 | + is($constituents[0]->nixname, "direct_aggregate", "'indirect_aggregate' has 'direct_aggregate' as single constituent"); |
| 42 | + }; |
| 43 | +}; |
| 44 | + |
| 45 | +subtest "* selects all except current aggregate" => sub { |
| 46 | + my $jobsetCtx = $ctx->makeJobset( |
| 47 | + expression => 'constituents-glob-all.nix', |
| 48 | + ); |
| 49 | + my $jobset = $jobsetCtx->{"jobset"}; |
| 50 | + |
| 51 | + my ($res, $stdout, $stderr) = captureStdoutStderr(60, |
| 52 | + ("hydra-eval-jobset", $jobsetCtx->{"project"}->name, $jobset->name) |
| 53 | + ); |
| 54 | + |
| 55 | + subtest "no eval errors" => sub { |
| 56 | + ok(utf8::decode($stderr), "Stderr output is UTF8-clean"); |
| 57 | + ok( |
| 58 | + $stderr !~ "aggregate job ‘ok_aggregate’ has a constituent .* that doesn't correspond to a Hydra build", |
| 59 | + "Catchall wildcard must not select itself as constituent" |
| 60 | + ); |
| 61 | + |
| 62 | + $jobset->discard_changes; # refresh from DB |
| 63 | + is( |
| 64 | + $jobset->errormsg, |
| 65 | + "", |
| 66 | + "eval-errors non-empty" |
| 67 | + ); |
| 68 | + }; |
| 69 | + |
| 70 | + my $builds = {}; |
| 71 | + for my $build ($jobset->builds) { |
| 72 | + $builds->{$build->job} = $build; |
| 73 | + } |
| 74 | + |
| 75 | + subtest "two constituents" => sub { |
| 76 | + ok(defined $builds->{"ok_aggregate"}, "'ok_aggregate' is part of the jobset evaluation"); |
| 77 | + my @constituents = $builds->{"ok_aggregate"}->constituents->all; |
| 78 | + is(2, scalar @constituents, "'ok_aggregate' has two constituents"); |
| 79 | + |
| 80 | + my @sortedConstituentNames = sort (map { $_->nixname } @constituents); |
| 81 | + |
| 82 | + is($sortedConstituentNames[0], "empty-dir-A", "first constituent of 'ok_aggregate' is 'empty-dir-A'"); |
| 83 | + is($sortedConstituentNames[1], "empty-dir-B", "second constituent of 'ok_aggregate' is 'empty-dir-B'"); |
| 84 | + }; |
| 85 | +}; |
| 86 | + |
| 87 | +subtest "trivial cycle check" => sub { |
| 88 | + my $jobsetCtx = $ctx->makeJobset( |
| 89 | + expression => 'constituents-cycle.nix', |
| 90 | + ); |
| 91 | + my $jobset = $jobsetCtx->{"jobset"}; |
| 92 | + |
| 93 | + my ($res, $stdout, $stderr) = captureStdoutStderr(60, |
| 94 | + ("hydra-eval-jobset", $jobsetCtx->{"project"}->name, $jobset->name) |
| 95 | + ); |
| 96 | + |
| 97 | + ok( |
| 98 | + $stderr =~ "Found dependency cycle between jobs 'indirect_aggregate' and 'ok_aggregate'", |
| 99 | + "Dependency cycle error is on stderr" |
| 100 | + ); |
| 101 | + |
| 102 | + ok(utf8::decode($stderr), "Stderr output is UTF8-clean"); |
| 103 | + |
| 104 | + $jobset->discard_changes; # refresh from DB |
| 105 | + like( |
| 106 | + $jobset->errormsg, |
| 107 | + qr/Dependency cycle: indirect_aggregate <-> ok_aggregate/, |
| 108 | + "eval-errors non-empty" |
| 109 | + ); |
| 110 | + |
| 111 | + is(0, $jobset->builds->count, "No builds should be scheduled"); |
| 112 | +}; |
| 113 | + |
| 114 | +subtest "cycle check with globbing" => sub { |
| 115 | + my $jobsetCtx = $ctx->makeJobset( |
| 116 | + expression => 'constituents-cycle-glob.nix', |
| 117 | + ); |
| 118 | + my $jobset = $jobsetCtx->{"jobset"}; |
| 119 | + |
| 120 | + my ($res, $stdout, $stderr) = captureStdoutStderr(60, |
| 121 | + ("hydra-eval-jobset", $jobsetCtx->{"project"}->name, $jobset->name) |
| 122 | + ); |
| 123 | + |
| 124 | + ok(utf8::decode($stderr), "Stderr output is UTF8-clean"); |
| 125 | + |
| 126 | + $jobset->discard_changes; # refresh from DB |
| 127 | + like( |
| 128 | + $jobset->errormsg, |
| 129 | + qr/aggregate job ‘indirect_aggregate’ failed with the error: Dependency cycle: indirect_aggregate <-> packages.constituentA/, |
| 130 | + "packages.constituentA error missing" |
| 131 | + ); |
| 132 | + |
| 133 | + # on this branch of Hydra, hydra-eval-jobset fails hard if an aggregate |
| 134 | + # job is broken. |
| 135 | + is(0, $jobset->builds->count, "Zero jobs are scheduled"); |
| 136 | +}; |
| 137 | + |
| 138 | +done_testing; |
0 commit comments