From aba0422865e277158ea0bc7b9f5e9c716a5640b6 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Fri, 7 Jan 2022 12:33:33 -0800 Subject: [PATCH 01/16] JobsetEval: allow restarting failed builds even with no eval to compare to --- src/lib/Hydra/Controller/JobsetEval.pm | 4 ++++ src/root/jobset-eval.tt | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/Hydra/Controller/JobsetEval.pm b/src/lib/Hydra/Controller/JobsetEval.pm index 6f6e7eab..ed0fe12e 100644 --- a/src/lib/Hydra/Controller/JobsetEval.pm +++ b/src/lib/Hydra/Controller/JobsetEval.pm @@ -83,6 +83,7 @@ sub view_GET { $c->stash->{removed} = []; $c->stash->{unfinished} = []; $c->stash->{aborted} = []; + $c->stash->{failed} = []; my $n = 0; foreach my $build (@builds) { @@ -119,6 +120,9 @@ sub view_GET { } else { push @{$c->stash->{new}}, $build if !$found; } + if ($build->buildstatus != 0) { + push @{$c->stash->{failed}}, $build; + } } $c->stash->{full} = ($c->req->params->{full} || "0") eq "1"; diff --git a/src/root/jobset-eval.tt b/src/root/jobset-eval.tt index 25315c66..8a8d92e4 100644 --- a/src/root/jobset-eval.tt +++ b/src/root/jobset-eval.tt @@ -51,7 +51,7 @@ c.uri_for(c.controller('JobsetEval').action_for('view'), [% IF unfinished.size > 0 %] Cancel all scheduled builds [% END %] - [% IF aborted.size > 0 || stillFail.size > 0 || nowFail.size > 0 %] + [% IF aborted.size > 0 || stillFail.size > 0 || nowFail.size > 0 || failed.size > 0 %] Restart all failed builds [% END %] [% IF aborted.size > 0 %] From 1349887974922b24e63d1bae548d4b02e7f0ff0b Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 10 Jan 2022 11:40:23 -0800 Subject: [PATCH 02/16] BuildDiff: split out from JobsetEval GET impl --- src/lib/Hydra/Controller/JobsetEval.pm | 51 +---------------- src/lib/Hydra/Helper/BuildDiff.pm | 76 ++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 49 deletions(-) create mode 100644 src/lib/Hydra/Helper/BuildDiff.pm diff --git a/src/lib/Hydra/Controller/JobsetEval.pm b/src/lib/Hydra/Controller/JobsetEval.pm index ed0fe12e..17b14ae1 100644 --- a/src/lib/Hydra/Controller/JobsetEval.pm +++ b/src/lib/Hydra/Controller/JobsetEval.pm @@ -6,6 +6,7 @@ use warnings; use base 'Hydra::Base::Controller::NixChannel'; use Hydra::Helper::Nix; use Hydra::Helper::CatalystUtils; +use Hydra::Helper::BuildDiff; use List::SomeUtils qw(uniq); @@ -75,55 +76,7 @@ sub view_GET { @builds = sort { cmpBuilds($a, $b) } @builds; @builds2 = sort { cmpBuilds($a, $b) } @builds2; - $c->stash->{stillSucceed} = []; - $c->stash->{stillFail} = []; - $c->stash->{nowSucceed} = []; - $c->stash->{nowFail} = []; - $c->stash->{new} = []; - $c->stash->{removed} = []; - $c->stash->{unfinished} = []; - $c->stash->{aborted} = []; - $c->stash->{failed} = []; - - my $n = 0; - foreach my $build (@builds) { - my $aborted = $build->finished != 0 && ($build->buildstatus == 3 || $build->buildstatus == 4); - my $d; - my $found = 0; - while ($n < scalar(@builds2)) { - my $build2 = $builds2[$n]; - my $d = cmpBuilds($build, $build2); - last if $d == -1; - if ($d == 0) { - $n++; - $found = 1; - if ($aborted) { - # do nothing - } elsif ($build->finished == 0 || $build2->finished == 0) { - push @{$c->stash->{unfinished}}, $build; - } elsif ($build->buildstatus == 0 && $build2->buildstatus == 0) { - push @{$c->stash->{stillSucceed}}, $build; - } elsif ($build->buildstatus != 0 && $build2->buildstatus != 0) { - push @{$c->stash->{stillFail}}, $build; - } elsif ($build->buildstatus == 0 && $build2->buildstatus != 0) { - push @{$c->stash->{nowSucceed}}, $build; - } elsif ($build->buildstatus != 0 && $build2->buildstatus == 0) { - push @{$c->stash->{nowFail}}, $build; - } else { die; } - last; - } - push @{$c->stash->{removed}}, { job => $build2->get_column('job'), system => $build2->get_column('system') }; - $n++; - } - if ($aborted) { - push @{$c->stash->{aborted}}, $build; - } else { - push @{$c->stash->{new}}, $build if !$found; - } - if ($build->buildstatus != 0) { - push @{$c->stash->{failed}}, $build; - } - } + buildDiff(@builds, @builds2); $c->stash->{full} = ($c->req->params->{full} || "0") eq "1"; diff --git a/src/lib/Hydra/Helper/BuildDiff.pm b/src/lib/Hydra/Helper/BuildDiff.pm new file mode 100644 index 00000000..7655bf4d --- /dev/null +++ b/src/lib/Hydra/Helper/BuildDiff.pm @@ -0,0 +1,76 @@ +package Hydra::Helper::BuildDiff; + +use utf8; +use strict; +use warnings; +use base 'Hydra::Base::Controller::NixChannel'; +use Hydra::Helper::Nix; +use Hydra::Helper::CatalystUtils; +use List::SomeUtils qw(uniq); + +our @ISA = qw(Exporter); +our @EXPORT = qw( + buildDiff +); + +use Data::Dumper; + +sub buildDiff { + my ($builds, $builds2) = @_; + + my $ret = [ + stillSucceed => [], + stillFail => [], + nowSucceed => [], + nowFail => [], + new => [], + removed => [], + unfinished => [], + aborted => [], + failed => [], + ]; + + my $n = 0; + foreach my $build (@{$builds}) { + my $aborted = $build->finished != 0 && ($build->buildstatus == 3 || $build->buildstatus == 4); + my $d; + my $found = 0; + while ($n < scalar($builds2)) { + my $build2 = @{$builds2}[$n]; + my $d = cmpBuilds($build, $build2); + last if $d == -1; + if ($d == 0) { + $n++; + $found = 1; + if ($aborted) { + # do nothing + } elsif ($build->finished == 0 || $build2->finished == 0) { + push @{$ret->{unfinished}}, $build; + } elsif ($build->buildstatus == 0 && $build2->buildstatus == 0) { + push @{$ret->{stillSucceed}}, $build; + } elsif ($build->buildstatus != 0 && $build2->buildstatus != 0) { + push @{$ret->{stillFail}}, $build; + } elsif ($build->buildstatus == 0 && $build2->buildstatus != 0) { + push @{$ret->{nowSucceed}}, $build; + } elsif ($build->buildstatus != 0 && $build2->buildstatus == 0) { + push @{$ret->{nowFail}}, $build; + } else { die; } + last; + } + push @{$ret->{removed}}, { job => $build2->get_column('job'), system => $build2->get_column('system') }; + $n++; + } + if ($aborted) { + push @{$ret->{aborted}}, $build; + } else { + push @{$ret->{new}}, $build if !$found; + } + if ($build->buildstatus != 0) { + push @{$ret->{failed}}, $build; + } + } + + return $ret; +} + +1; \ No newline at end of file From 0eb952d72df12bd31ac2033bc72143ca950bc834 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 10 Jan 2022 11:40:59 -0800 Subject: [PATCH 03/16] t/BuildDiff: init --- t/Helper/BuildDiff.t | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 t/Helper/BuildDiff.t diff --git a/t/Helper/BuildDiff.t b/t/Helper/BuildDiff.t new file mode 100644 index 00000000..86bf3fba --- /dev/null +++ b/t/Helper/BuildDiff.t @@ -0,0 +1,27 @@ +use strict; +use warnings; +use Setup; +use Test2::V0; + +use Hydra::Helper::BuildDiff; + +my $ctx = test_context(); + +subtest "response" => sub { + my $ret = buildDiff([], []); + is($ret, [ + stillSucceed => [], + stillFail => [], + nowSucceed => [], + nowFail => [], + new => [], + removed => [], + unfinished => [], + aborted => [], + failed => [], + ]); +}; + +is(1, 1); + +done_testing; From 0c51f3ca7dbf71e5aa87a3d73b0acbf24063b256 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 10 Jan 2022 10:02:39 -0800 Subject: [PATCH 04/16] BuildDiff: make actual hash ref --- src/lib/Hydra/Helper/BuildDiff.pm | 4 ++-- t/Helper/BuildDiff.t | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/Hydra/Helper/BuildDiff.pm b/src/lib/Hydra/Helper/BuildDiff.pm index 7655bf4d..fb6e6543 100644 --- a/src/lib/Hydra/Helper/BuildDiff.pm +++ b/src/lib/Hydra/Helper/BuildDiff.pm @@ -18,7 +18,7 @@ use Data::Dumper; sub buildDiff { my ($builds, $builds2) = @_; - my $ret = [ + my $ret = { stillSucceed => [], stillFail => [], nowSucceed => [], @@ -28,7 +28,7 @@ sub buildDiff { unfinished => [], aborted => [], failed => [], - ]; + }; my $n = 0; foreach my $build (@{$builds}) { diff --git a/t/Helper/BuildDiff.t b/t/Helper/BuildDiff.t index 86bf3fba..35d7e8c2 100644 --- a/t/Helper/BuildDiff.t +++ b/t/Helper/BuildDiff.t @@ -9,7 +9,7 @@ my $ctx = test_context(); subtest "response" => sub { my $ret = buildDiff([], []); - is($ret, [ + is($ret, { stillSucceed => [], stillFail => [], nowSucceed => [], @@ -19,7 +19,7 @@ subtest "response" => sub { unfinished => [], aborted => [], failed => [], - ]); + }); }; is(1, 1); From ec98bdaaaa4af85be664229418a6998696f81abe Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 10 Jan 2022 10:35:07 -0800 Subject: [PATCH 05/16] BuildDiff: move cmdBuilds from Controller/JobsetEval --- src/lib/Hydra/Controller/JobsetEval.pm | 9 --------- src/lib/Hydra/Helper/BuildDiff.pm | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/lib/Hydra/Controller/JobsetEval.pm b/src/lib/Hydra/Controller/JobsetEval.pm index 17b14ae1..d1aef2bd 100644 --- a/src/lib/Hydra/Controller/JobsetEval.pm +++ b/src/lib/Hydra/Controller/JobsetEval.pm @@ -64,18 +64,9 @@ sub view_GET { $c->stash->{otherEval} = $eval2 if defined $eval2; - sub cmpBuilds { - my ($left, $right) = @_; - return $left->get_column('job') cmp $right->get_column('job') - || $left->get_column('system') cmp $right->get_column('system') - } - my @builds = $eval->builds->search($filter, { columns => [@buildListColumns] }); my @builds2 = defined $eval2 ? $eval2->builds->search($filter, { columns => [@buildListColumns] }) : (); - @builds = sort { cmpBuilds($a, $b) } @builds; - @builds2 = sort { cmpBuilds($a, $b) } @builds2; - buildDiff(@builds, @builds2); $c->stash->{full} = ($c->req->params->{full} || "0") eq "1"; diff --git a/src/lib/Hydra/Helper/BuildDiff.pm b/src/lib/Hydra/Helper/BuildDiff.pm index fb6e6543..08308a6d 100644 --- a/src/lib/Hydra/Helper/BuildDiff.pm +++ b/src/lib/Hydra/Helper/BuildDiff.pm @@ -15,6 +15,15 @@ our @EXPORT = qw( use Data::Dumper; +sub cmpBuilds { + my ($left, $right) = @_; + return $left->get_column('job') cmp $right->get_column('job') + || $left->get_column('system') cmp $right->get_column('system') +} + + # $builds = sort { cmpBuilds($a, $b) } $builds; + # $builds2 = sort { cmpBuilds($a, $b) } $builds2; + sub buildDiff { my ($builds, $builds2) = @_; From ff12218d0274a78caf668186b8d3ecf6a84eb93d Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 10 Jan 2022 10:35:39 -0800 Subject: [PATCH 06/16] BuildDiff: cleanup imports and make slightly more readable --- src/lib/Hydra/Helper/BuildDiff.pm | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/lib/Hydra/Helper/BuildDiff.pm b/src/lib/Hydra/Helper/BuildDiff.pm index 08308a6d..6dc534df 100644 --- a/src/lib/Hydra/Helper/BuildDiff.pm +++ b/src/lib/Hydra/Helper/BuildDiff.pm @@ -3,10 +3,6 @@ package Hydra::Helper::BuildDiff; use utf8; use strict; use warnings; -use base 'Hydra::Base::Controller::NixChannel'; -use Hydra::Helper::Nix; -use Hydra::Helper::CatalystUtils; -use List::SomeUtils qw(uniq); our @ISA = qw(Exporter); our @EXPORT = qw( @@ -66,7 +62,8 @@ sub buildDiff { } else { die; } last; } - push @{$ret->{removed}}, { job => $build2->get_column('job'), system => $build2->get_column('system') }; + my $job_system = { job => $build2->get_column('job'), system => $build2->get_column('system') }; + push @{$ret->{removed}}, $job_system; $n++; } if ($aborted) { From 458214381df93753fbd79ec939023946a52c7a50 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 10 Jan 2022 10:35:58 -0800 Subject: [PATCH 07/16] BuildDiff: document what the inputs mean They were tripping me up, so it helped to know exactly what they were at the ~point they're used. --- src/lib/Hydra/Helper/BuildDiff.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/Hydra/Helper/BuildDiff.pm b/src/lib/Hydra/Helper/BuildDiff.pm index 6dc534df..ad5cf59b 100644 --- a/src/lib/Hydra/Helper/BuildDiff.pm +++ b/src/lib/Hydra/Helper/BuildDiff.pm @@ -22,6 +22,7 @@ sub cmpBuilds { sub buildDiff { my ($builds, $builds2) = @_; + # $builds is the list of current builds, and $builds2 is the list of previous (compared-to) builds my $ret = { stillSucceed => [], From ceb81e7d7856a183928f91f1ec47e5f8f2c19236 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 10 Jan 2022 10:36:25 -0800 Subject: [PATCH 08/16] BuildDiff: actual list reference to $builds2 --- src/lib/Hydra/Helper/BuildDiff.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Hydra/Helper/BuildDiff.pm b/src/lib/Hydra/Helper/BuildDiff.pm index ad5cf59b..612ecbf3 100644 --- a/src/lib/Hydra/Helper/BuildDiff.pm +++ b/src/lib/Hydra/Helper/BuildDiff.pm @@ -41,7 +41,7 @@ sub buildDiff { my $aborted = $build->finished != 0 && ($build->buildstatus == 3 || $build->buildstatus == 4); my $d; my $found = 0; - while ($n < scalar($builds2)) { + while ($n < scalar(@{$builds2})) { my $build2 = @{$builds2}[$n]; my $d = cmpBuilds($build, $build2); last if $d == -1; From 220ccc68dfec44e8eaa41bd55923ce74b4f994e1 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 10 Jan 2022 10:36:55 -0800 Subject: [PATCH 09/16] t/BuildDiff: test diffing two jobs --- t/Helper/BuildDiff.t | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/t/Helper/BuildDiff.t b/t/Helper/BuildDiff.t index 35d7e8c2..b797f758 100644 --- a/t/Helper/BuildDiff.t +++ b/t/Helper/BuildDiff.t @@ -7,6 +7,11 @@ use Hydra::Helper::BuildDiff; my $ctx = test_context(); +my $builds = $ctx->makeAndEvaluateJobset( + expression => "basic.nix", + build => 1 +); + subtest "response" => sub { my $ret = buildDiff([], []); is($ret, { @@ -22,6 +27,40 @@ subtest "response" => sub { }); }; -is(1, 1); +subtest "2 different jobs" => sub { + my $ret = buildDiff([$builds->{"succeed_with_failed"}], [$builds->{"empty_dir"}]); + + is($ret->{stillSucceed}, [], "stillSucceed"); + is($ret->{stillFail}, [], "stillFail"); + is($ret->{nowSucceed}, [], "nowSucceed"); + is($ret->{nowFail}, [], "nowFail"); + is($ret->{unfinished}, [], "unfinished"); + is($ret->{aborted}, [], "aborted"); + + is(scalar(@{$ret->{new}}), 1, "list of new jobs is 1 element long"); + is( + $ret->{new}[0]->get_column('id'), + $builds->{"succeed_with_failed"}->get_column('id'), + "succeed_with_failed is a new job" + ); + + is(scalar(@{$ret->{failed}}), 1, "list of failed jobs is 1 element long"); + is( + $ret->{failed}[0]->get_column('id'), + $builds->{"succeed_with_failed"}->get_column('id'), + "succeed_with_failed is a failed job" + ); + + is( + $ret->{removed}, + [ + { + job => $builds->{"empty_dir"}->get_column('job'), + system => $builds->{"empty_dir"}->get_column('system') + } + ], + "empty_dir is a removed job" + ); +}; done_testing; From 157a02bff7a1b156176ce8b02a26a85d8cdf7fc6 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 10 Jan 2022 10:39:06 -0800 Subject: [PATCH 10/16] t/BuildDiff: slightly refactor empty test to be more readable --- t/Helper/BuildDiff.t | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/t/Helper/BuildDiff.t b/t/Helper/BuildDiff.t index b797f758..3bdce17e 100644 --- a/t/Helper/BuildDiff.t +++ b/t/Helper/BuildDiff.t @@ -12,19 +12,23 @@ my $builds = $ctx->makeAndEvaluateJobset( build => 1 ); -subtest "response" => sub { +subtest "empty diff" => sub { my $ret = buildDiff([], []); - is($ret, { - stillSucceed => [], - stillFail => [], - nowSucceed => [], - nowFail => [], - new => [], - removed => [], - unfinished => [], - aborted => [], - failed => [], - }); + is( + $ret, + { + stillSucceed => [], + stillFail => [], + nowSucceed => [], + nowFail => [], + new => [], + removed => [], + unfinished => [], + aborted => [], + failed => [], + }, + "empty list of jobs returns empty diff" + ); }; subtest "2 different jobs" => sub { From 1ca786561f4b601b9aa7d5db0e979b9e7d227d9c Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 10 Jan 2022 10:46:02 -0800 Subject: [PATCH 11/16] t/JobsetEval: test GETing the eval page --- t/Controller/JobsetEval/fetch.t | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 t/Controller/JobsetEval/fetch.t diff --git a/t/Controller/JobsetEval/fetch.t b/t/Controller/JobsetEval/fetch.t new file mode 100644 index 00000000..b129de75 --- /dev/null +++ b/t/Controller/JobsetEval/fetch.t @@ -0,0 +1,28 @@ +use feature 'unicode_strings'; +use strict; +use warnings; +use Setup; +use JSON::MaybeXS qw(decode_json encode_json); + +my %ctx = test_init(); + +require Hydra::Schema; +require Hydra::Model::DB; +require Hydra::Helper::Nix; + +use Test2::V0; +require Catalyst::Test; +Catalyst::Test->import('Hydra'); +use HTTP::Request::Common qw(POST PUT GET DELETE); + +my $db = Hydra::Model::DB->new; +hydra_setup($db); + +my $jobset = createBaseJobset("basic", "basic.nix", $ctx{jobsdir}); +ok(evalSucceeds($jobset), "Evaluating jobs/basic.nix should exit with return code 0"); + +my ($eval, @evals) = $jobset->jobsetevals; +my $fetch = request(GET '/eval/' . $eval->id); +is($fetch->code, 200, "eval page is 200"); + +done_testing; From 98375e9086be857ba654d3be18c489c9434ef627 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 10 Jan 2022 10:50:34 -0800 Subject: [PATCH 12/16] BuildDiff: bring back the sort --- src/lib/Hydra/Helper/BuildDiff.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/Hydra/Helper/BuildDiff.pm b/src/lib/Hydra/Helper/BuildDiff.pm index 612ecbf3..56d7ddae 100644 --- a/src/lib/Hydra/Helper/BuildDiff.pm +++ b/src/lib/Hydra/Helper/BuildDiff.pm @@ -17,13 +17,13 @@ sub cmpBuilds { || $left->get_column('system') cmp $right->get_column('system') } - # $builds = sort { cmpBuilds($a, $b) } $builds; - # $builds2 = sort { cmpBuilds($a, $b) } $builds2; - sub buildDiff { my ($builds, $builds2) = @_; # $builds is the list of current builds, and $builds2 is the list of previous (compared-to) builds + $builds = [sort { cmpBuilds($a, $b) } @{$builds}]; + $builds2 = [sort { cmpBuilds($a, $b) } @{$builds2}]; + my $ret = { stillSucceed => [], stillFail => [], From ef6a2c96e7cd602594d8e8b0fe64c4d3c7bc767d Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 10 Jan 2022 10:54:54 -0800 Subject: [PATCH 13/16] JobsetEval: add the result of buildDiff to $c->stash --- src/lib/Hydra/Controller/JobsetEval.pm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib/Hydra/Controller/JobsetEval.pm b/src/lib/Hydra/Controller/JobsetEval.pm index d1aef2bd..30179d49 100644 --- a/src/lib/Hydra/Controller/JobsetEval.pm +++ b/src/lib/Hydra/Controller/JobsetEval.pm @@ -67,7 +67,16 @@ sub view_GET { my @builds = $eval->builds->search($filter, { columns => [@buildListColumns] }); my @builds2 = defined $eval2 ? $eval2->builds->search($filter, { columns => [@buildListColumns] }) : (); - buildDiff(@builds, @builds2); + my $diff = buildDiff([@builds], [@builds2]); + $c->stash->{stillSucceed} = $diff->{stillSucceed}; + $c->stash->{stillFail} = $diff->{stillFail}; + $c->stash->{nowSucceed} = $diff->{nowSucceed}; + $c->stash->{nowFail} = $diff->{nowFail}; + $c->stash->{new} = $diff->{new}; + $c->stash->{removed} = $diff->{removed}; + $c->stash->{unfinished} = $diff->{unfinished}; + $c->stash->{aborted} = $diff->{aborted}; + $c->stash->{failed} = $diff->{failed}; $c->stash->{full} = ($c->req->params->{full} || "0") eq "1"; From b98dbe01c3641dd8e0afe37768abe8724b35b771 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 10 Jan 2022 10:57:28 -0800 Subject: [PATCH 14/16] BuildDiff: slight cleanup Remove debugging Data::Dumper import, make comment describing function inputs more readable. --- src/lib/Hydra/Helper/BuildDiff.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib/Hydra/Helper/BuildDiff.pm b/src/lib/Hydra/Helper/BuildDiff.pm index 56d7ddae..434fa913 100644 --- a/src/lib/Hydra/Helper/BuildDiff.pm +++ b/src/lib/Hydra/Helper/BuildDiff.pm @@ -9,8 +9,6 @@ our @EXPORT = qw( buildDiff ); -use Data::Dumper; - sub cmpBuilds { my ($left, $right) = @_; return $left->get_column('job') cmp $right->get_column('job') @@ -18,8 +16,9 @@ sub cmpBuilds { } sub buildDiff { + # $builds is the list of current builds + # $builds2 is the list of previous (to-be-compared-to) builds my ($builds, $builds2) = @_; - # $builds is the list of current builds, and $builds2 is the list of previous (compared-to) builds $builds = [sort { cmpBuilds($a, $b) } @{$builds}]; $builds2 = [sort { cmpBuilds($a, $b) } @{$builds2}]; From 92bd0fae7dade7662e9a76226c8b8504793b4fdb Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 10 Jan 2022 11:12:18 -0800 Subject: [PATCH 15/16] t/BuildDiff: test jobs without previous history --- t/Helper/BuildDiff.t | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/t/Helper/BuildDiff.t b/t/Helper/BuildDiff.t index 3bdce17e..243bb596 100644 --- a/t/Helper/BuildDiff.t +++ b/t/Helper/BuildDiff.t @@ -67,4 +67,40 @@ subtest "2 different jobs" => sub { ); }; +subtest "failed job with no previous history" => sub { + my $ret = buildDiff([$builds->{"fails"}], []); + + is(scalar(@{$ret->{failed}}), 1, "list of failed jobs is 1 element long"); + is( + $ret->{failed}[0]->get_column('id'), + $builds->{"fails"}->get_column('id'), + "fails is a failed job" + ); +}; + +subtest "not-yet-built job with no previous history" => sub { + my $builds = $ctx->makeAndEvaluateJobset( + expression => "build-products.nix", + build => 0 + ); + + my $ret = buildDiff([$builds->{"simple"}], []); + + is($ret->{stillSucceed}, [], "stillSucceed"); + is($ret->{stillFail}, [], "stillFail"); + is($ret->{nowSucceed}, [], "nowSucceed"); + is($ret->{nowFail}, [], "nowFail"); + is($ret->{removed}, [], "removed"); + is($ret->{unfinished}, [], "unfinished"); + is($ret->{aborted}, [], "aborted"); + is($ret->{failed}, [], "failed"); + + is(scalar(@{$ret->{new}}), 1, "list of new jobs is 1 element long"); + is( + $ret->{new}[0]->get_column('id'), + $builds->{"simple"}->get_column('id'), + "simple is a new job" + ); +}; + done_testing; From 9b12a88d8163682d5459133a8db7a0064681edf6 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 10 Jan 2022 11:13:47 -0800 Subject: [PATCH 16/16] BuildDiff: ensure buildstatus is defined buildstatus won't be defined if e.g. a build is queued but none have failed. --- src/lib/Hydra/Helper/BuildDiff.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Hydra/Helper/BuildDiff.pm b/src/lib/Hydra/Helper/BuildDiff.pm index 434fa913..cd8c7691 100644 --- a/src/lib/Hydra/Helper/BuildDiff.pm +++ b/src/lib/Hydra/Helper/BuildDiff.pm @@ -71,7 +71,7 @@ sub buildDiff { } else { push @{$ret->{new}}, $build if !$found; } - if ($build->buildstatus != 0) { + if (defined $build->buildstatus && $build->buildstatus != 0) { push @{$ret->{failed}}, $build; } }