From 5d169e3a2eea27f80981ab419613d5c5e03880c8 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sun, 20 Feb 2022 11:54:14 -0500 Subject: [PATCH 1/5] Add a test validating direct and indirect constituents --- t/jobs/constituents.nix | 40 +++++++++++++++++++ t/queue-runner/direct-indirect-constituents.t | 35 ++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 t/jobs/constituents.nix create mode 100644 t/queue-runner/direct-indirect-constituents.t diff --git a/t/jobs/constituents.nix b/t/jobs/constituents.nix new file mode 100644 index 00000000..5b7106b9 --- /dev/null +++ b/t/jobs/constituents.nix @@ -0,0 +1,40 @@ +with import ./config.nix; +rec { + constituentA = mkDerivation { + name = "empty-dir-A"; + builder = ./empty-dir-builder.sh; + }; + + constituentB = mkDerivation { + name = "empty-dir-B"; + builder = ./empty-dir-builder.sh; + }; + + direct_aggregate = mkDerivation { + name = "direct_aggregate"; + _hydraAggregate = true; + constituents = [ + constituentA + ]; + builder = ./empty-dir-builder.sh; + }; + + indirect_aggregate = mkDerivation { + name = "indirect_aggregate"; + _hydraAggregate = true; + constituents = [ + "constituentA" + ]; + builder = ./empty-dir-builder.sh; + }; + + mixed_aggregate = mkDerivation { + name = "mixed_aggregate"; + _hydraAggregate = true; + constituents = [ + "constituentA" + constituentB + ]; + builder = ./empty-dir-builder.sh; + }; +} diff --git a/t/queue-runner/direct-indirect-constituents.t b/t/queue-runner/direct-indirect-constituents.t new file mode 100644 index 00000000..35370450 --- /dev/null +++ b/t/queue-runner/direct-indirect-constituents.t @@ -0,0 +1,35 @@ +use strict; +use warnings; +use Setup; +use Test2::V0; + +my $ctx = test_context(); + +my $builds = $ctx->makeAndEvaluateJobset( + expression => 'constituents.nix', +); + +my $constituentBuildA = $builds->{"constituentA"}; +my $constituentBuildB = $builds->{"constituentB"}; + +my $eval = $constituentBuildA->jobsetevals->first(); +is($eval->evaluationerror->errormsg, ""); + +subtest "Verifying the direct aggregate" => sub { + my $aggBuild = $builds->{"direct_aggregate"}; + is($aggBuild->constituents->first()->id, $constituentBuildA->id, "The ID of the constituent is correct"); +}; + +subtest "Verifying the indirect aggregate" => sub { + my $indirectBuild = $builds->{"indirect_aggregate"}; + is($indirectBuild->constituents->first()->id, $constituentBuildA->id, "The ID of the constituent is correct"); +}; + +subtest "Verifying a mix of direct and indirect aggregate references" => sub { + my $mixedBuild = $builds->{"mixed_aggregate"}; + my ($constituentA, $constituentB) = $mixedBuild->constituents()->search({}, {order_by => { -asc => "job"} }); + is($constituentA->id, $constituentBuildA->id, "The ID of the constituent is correct"); + is($constituentB->id, $constituentBuildB->id, "The ID of the constituent is correct"); +}; + +done_testing; From be46f0216442577718c8a9d640b4021ba1c8b515 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sun, 20 Feb 2022 11:55:31 -0500 Subject: [PATCH 2/5] tests: relocate evaluator tests --- t/{ => evaluator}/evaluate-basic.t | 0 t/{ => evaluator}/evaluate-dependent-jobsets.t | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename t/{ => evaluator}/evaluate-basic.t (100%) rename t/{ => evaluator}/evaluate-dependent-jobsets.t (100%) diff --git a/t/evaluate-basic.t b/t/evaluator/evaluate-basic.t similarity index 100% rename from t/evaluate-basic.t rename to t/evaluator/evaluate-basic.t diff --git a/t/evaluate-dependent-jobsets.t b/t/evaluator/evaluate-dependent-jobsets.t similarity index 100% rename from t/evaluate-dependent-jobsets.t rename to t/evaluator/evaluate-dependent-jobsets.t From e0921eba0a938172c53128de8b91e8310a74a51e Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sun, 20 Feb 2022 12:18:11 -0500 Subject: [PATCH 3/5] Create a basic test which verifies we can't delete the derivation of aggregate jobs --- t/evaluator/evaluate-constituents-gc.t | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 t/evaluator/evaluate-constituents-gc.t diff --git a/t/evaluator/evaluate-constituents-gc.t b/t/evaluator/evaluate-constituents-gc.t new file mode 100644 index 00000000..a9b23e6c --- /dev/null +++ b/t/evaluator/evaluate-constituents-gc.t @@ -0,0 +1,20 @@ +use strict; +use warnings; +use Setup; +use Test2::V0; + +my $ctx = test_context(); + +my $builds = $ctx->makeAndEvaluateJobset( + expression => 'constituents.nix', +); + +my $constituentA = $builds->{"constituentA"}; +my $directAggregate = $builds->{"direct_aggregate"}; +my $indirectAggregate = $builds->{"indirect_aggregate"}; + +is(system('nix-store', '--delete', $constituentA->drvpath), 256, "Deleting a constituent derivation fails"); +is(system('nix-store', '--delete', $directAggregate->drvpath), 256, "Deleting the direct aggregate derivation fails"); +is(system('nix-store', '--delete', $indirectAggregate->drvpath), 256, "Deleting the indirect aggregate derivation fails"); + +done_testing; From 290e0653ad0121b80e53dfc0a5f9eed7540049ff Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sun, 20 Feb 2022 12:15:10 -0500 Subject: [PATCH 4/5] hydra-eval-jobs: GC root aggregate jobs --- src/hydra-eval-jobs/hydra-eval-jobs.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/hydra-eval-jobs/hydra-eval-jobs.cc b/src/hydra-eval-jobs/hydra-eval-jobs.cc index acffe1d1..897956bf 100644 --- a/src/hydra-eval-jobs/hydra-eval-jobs.cc +++ b/src/hydra-eval-jobs/hydra-eval-jobs.cc @@ -504,6 +504,16 @@ int main(int argc, char * * argv) job.erase("namedConstituents"); + /* Register the derivation as a GC root. !!! This + registers roots for jobs that we may have already + done. */ + auto localStore = store.dynamic_pointer_cast(); + if (gcRootsDir != "" && localStore) { + Path root = gcRootsDir + "/" + std::string(baseNameOf((std::string) job["drvPath"])); + if (!pathExists(root)) + localStore->addPermRoot(localStore->parseStorePath((std::string) job["drvPath"]), root); + } + if (!brokenJobs.empty()) { std::stringstream ss; for (const auto& [jobName, error] : brokenJobs) { From 9316544abf53183fa7149b272aed054d0457697e Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Mon, 21 Feb 2022 12:41:21 -0500 Subject: [PATCH 5/5] src/hydra-eval-jobs/hydra-eval-jobs.cc: .get for drvPath Co-authored-by: Kayla Fire --- src/hydra-eval-jobs/hydra-eval-jobs.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hydra-eval-jobs/hydra-eval-jobs.cc b/src/hydra-eval-jobs/hydra-eval-jobs.cc index 897956bf..44a273a9 100644 --- a/src/hydra-eval-jobs/hydra-eval-jobs.cc +++ b/src/hydra-eval-jobs/hydra-eval-jobs.cc @@ -509,9 +509,10 @@ int main(int argc, char * * argv) done. */ auto localStore = store.dynamic_pointer_cast(); if (gcRootsDir != "" && localStore) { - Path root = gcRootsDir + "/" + std::string(baseNameOf((std::string) job["drvPath"])); + auto drvPath = job["drvPath"].get(); + Path root = gcRootsDir + "/" + std::string(baseNameOf(drvPath)); if (!pathExists(root)) - localStore->addPermRoot(localStore->parseStorePath((std::string) job["drvPath"]), root); + localStore->addPermRoot(localStore->parseStorePath(drvPath), root); } if (!brokenJobs.empty()) {