From 952f629b7cf1ea918023747a198efff1d1686457 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Fri, 21 Jan 2022 15:13:52 -0500 Subject: [PATCH] Test the queue runner in the scenario where a dependency is available in the cache but GC'd locally, where we're building locally --- t/jobs/dependencies/dependency.nix | 17 +++++++ t/jobs/dependencies/dependentOnly.nix | 4 ++ t/jobs/dependencies/underlyingOnly.nix | 4 ++ .../build-locally-with-substitutable-path.t | 51 +++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 t/jobs/dependencies/dependency.nix create mode 100644 t/jobs/dependencies/dependentOnly.nix create mode 100644 t/jobs/dependencies/underlyingOnly.nix create mode 100644 t/queue-runner/build-locally-with-substitutable-path.t diff --git a/t/jobs/dependencies/dependency.nix b/t/jobs/dependencies/dependency.nix new file mode 100644 index 00000000..f528bdc8 --- /dev/null +++ b/t/jobs/dependencies/dependency.nix @@ -0,0 +1,17 @@ +{ exposeUnderlyingJob, exposeDependentJob }: +with import ../config.nix; +let + underlyingJob = mkDerivation { + name = "underlying-job"; + builder = ../empty-dir-builder.sh; + }; + + dependentJob = mkDerivation { + name = "dependent-job"; + builder = ../empty-dir-builder.sh; + inherit underlyingJob; + }; +in +(if exposeUnderlyingJob then { inherit underlyingJob; } else { }) // +(if exposeDependentJob then { inherit dependentJob; } else { }) // +{ } diff --git a/t/jobs/dependencies/dependentOnly.nix b/t/jobs/dependencies/dependentOnly.nix new file mode 100644 index 00000000..edf8a912 --- /dev/null +++ b/t/jobs/dependencies/dependentOnly.nix @@ -0,0 +1,4 @@ +import ./dependency.nix { + exposeUnderlyingJob = false; + exposeDependentJob = true; +} diff --git a/t/jobs/dependencies/underlyingOnly.nix b/t/jobs/dependencies/underlyingOnly.nix new file mode 100644 index 00000000..106d17fe --- /dev/null +++ b/t/jobs/dependencies/underlyingOnly.nix @@ -0,0 +1,4 @@ +import ./dependency.nix { + exposeUnderlyingJob = true; + exposeDependentJob = false; +} diff --git a/t/queue-runner/build-locally-with-substitutable-path.t b/t/queue-runner/build-locally-with-substitutable-path.t new file mode 100644 index 00000000..f335d284 --- /dev/null +++ b/t/queue-runner/build-locally-with-substitutable-path.t @@ -0,0 +1,51 @@ +use strict; +use warnings; +use Setup; +use Data::Dumper; +use Test2::V0; +my $ctx = test_context( + use_external_destination_store => 1 +); + +# This test is regarding https://github.com/NixOS/hydra/pull/1126 +# +# A hydra instance was regularly failing to build derivations with: +# +# possibly transient failure building ‘/nix/store/X.drv’ on ‘localhost’: +# dependency '/nix/store/Y' of '/nix/store/Y.drv' does not exist, +# and substitution is disabled +# +# However it would only fail when building on localhost, and it would only +# fail if the build output was already in the binary cache. +# +# This test replicates this scenario by having two jobs, underlyingJob and +# dependentJob. dependentJob depends on underlyingJob. We first build +# underlyingJob and copy it to an external cache. Then forcefully delete +# the output of underlyingJob, and build dependentJob. In order to pass +# it must either rebuild underlyingJob or fetch it from the cache. + + +subtest "Building, caching, and then garbage collecting the underlying job" => sub { + my $builds = $ctx->makeAndEvaluateJobset( + expression => "dependencies/underlyingOnly.nix", + build => 1 + ); + + my $path = $builds->{"underlyingJob"}->buildoutputs->find({ name => "out" })->path; + + ok(unlink(Hydra::Helper::Nix::gcRootFor($path)), "Unlinking the GC root for underlying Dependency succeeds"); + + (my $ret, my $stdout, my $stderr) = captureStdoutStderr(1, "nix-store", "--delete", $path); + is($ret, 0, "Deleting the underlying dependency should succeed"); +}; + +subtest "Building the dependent job should now succeed, even though we're missing a local dependency" => sub { + my $builds = $ctx->makeAndEvaluateJobset( + expression => "dependencies/dependentOnly.nix" + ); + + ok(runBuild($builds->{"dependentJob"}), "building the job should succeed"); +}; + + +done_testing;