Skip to content

Commit cd235f7

Browse files
authored
Merge pull request #1642 from obsidiansystems/test-multi-store
Do not share store between builder and queue runner in unit tests
2 parents 5175e8a + 08c10ec commit cd235f7

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

subprojects/hydra-tests/lib/HydraTestContext.pm

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,26 @@ sub new {
4747
# up, but can be kept to aid in debugging test failures.
4848
my $dir = File::Temp->newdir(CLEANUP => 0);
4949

50+
# Logical store dir — shared between evaluator and builder so store
51+
# paths are compatible. The builder's physical store matches this
52+
# (physical = logical), which is required on Darwin where we cannot
53+
# use sandboxed builds.
54+
my $builder = { root => "$dir/builder" };
55+
make_path($builder->{root});
56+
$builder->{nix_store_dir} = "$builder->{root}/nix/store";
57+
$builder->{nix_state_dir} = "$builder->{root}/nix/var/nix";
58+
$builder->{nix_log_dir} = "$builder->{root}/nix/var/log/nix";
59+
$builder->{nix_store_uri} = "local?root=$builder->{root}&store=$builder->{nix_store_dir}";
60+
$builder->{nix_conf_dir} = "$dir/nix/etc/nix";
61+
5062
# Physical dirs for centralized services (queue runner, main web app, etc.)
5163
my $central = { root => "$dir/central" };
64+
make_path($central->{root});
5265
$central->{hydra_data} = "$dir/hydra-data";
53-
$central->{nix_conf_dir} = "$dir/nix/etc/nix";
5466
$central->{hydra_config_file} = "$dir/hydra.conf";
55-
$central->{nix_store_dir} = "$central->{root}/nix/store";
67+
$central->{nix_conf_dir} = "$dir/nix/etc/nix";
68+
# Builder and central must agree on logical store dir.
69+
$central->{nix_store_dir} = $builder->{nix_store_dir};
5670
$central->{nix_state_dir} = "$central->{root}/nix/var/nix";
5771
$central->{nix_log_dir} = "$central->{root}/nix/var/log/nix";
5872
$central->{nix_store_uri} = "local?root=$central->{root}&store=$central->{nix_store_dir}";
@@ -91,6 +105,7 @@ sub new {
91105
_db => undef,
92106
db_handle => $pgsql,
93107
tmpdir => $dir,
108+
builder => $builder,
94109
central => $central,
95110
testdir => abs_path(dirname(__FILE__) . "/.."),
96111
jobsdir => $jobsdir,

subprojects/hydra-tests/lib/QueueRunnerBuildOne.pm

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,14 @@ sub runBuilds {
127127
_wait_for($ua, "$base_url/status")
128128
or die "Timed out waiting for queue-runner REST server\n";
129129

130-
# TODO Start the builder with its own store settings.
130+
# Start the builder with its own store settings.
131131
{
132-
local $ENV{NIX_REMOTE} = $ctx->{central}{nix_store_uri};
133-
local $ENV{NIX_CONF_DIR} = $ctx->{central}{nix_conf_dir};
134-
local $ENV{NIX_STATE_DIR} = $ctx->{central}{nix_state_dir};
135-
local $ENV{NIX_STORE_DIR} = $ctx->{central}{nix_store_dir};
132+
local $ENV{NIX_REMOTE} = $ctx->{builder}{nix_store_uri};
133+
local $ENV{NIX_CONF_DIR} = $ctx->{builder}{nix_conf_dir};
134+
local $ENV{NIX_STATE_DIR} = $ctx->{builder}{nix_state_dir};
135+
# TODO: hydra-builder reads NIX_STORE_DIR to report its
136+
# store dir to the queue runner; should use the store URI instead.
137+
local $ENV{NIX_STORE_DIR} = $ctx->{builder}{nix_store_dir};
136138
local $ENV{RUST_LOG} = "hydra_builder=debug,info";
137139
local $ENV{NO_COLOR} = "1";
138140
$bl_harness = IPC::Run::start(

subprojects/hydra-tests/queue-runner/notifications.t

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,44 +32,49 @@ my $ctx = test_context(
3232
# locally. For completeness, we also verify that we can substitute
3333
# the build locally.
3434

35+
# Use the builder store (physical = logical) for direct nix-* calls,
36+
# because the central store has physical != logical which breaks nix-build
37+
# when the derivation references paths outside the logical store dir.
38+
my $store_uri = $ctx->{builder}{nix_store_uri};
39+
3540
subtest "Pre-build the job, upload to the cache, and then delete locally" => sub {
3641
my $outlink = $ctx->tmpdir . "/basic-canbesubstituted";
3742
my ($res, $stdout, $stderr);
38-
($res) = $ctx->capture_cmd(60, 'nix-build', $ctx->jobsdir . '/notifications.nix', '-A', 'canbesubstituted', '--out-link', $outlink);
43+
($res) = $ctx->capture_cmd(60, 'nix-build', '--store', $store_uri, $ctx->jobsdir . '/notifications.nix', '-A', 'canbesubstituted', '--out-link', $outlink);
3944
is($res, 0, "Building notifications.nix succeeded");
40-
($res) = $ctx->capture_cmd(60, 'nix', 'copy', '--to', "file://${binarycachedir}", $outlink);
45+
($res) = $ctx->capture_cmd(60, 'nix', '--store', $store_uri, 'copy', '--to', "file://${binarycachedir}", $outlink);
4146
is($res, 0, "Copying the closure to the binary cache succeeded");
4247
my $outpath = readlink($outlink);
4348

4449
# Delete the store path and all of the system's garbage
4550
is(unlink($outlink), 1, "Deleting the GC root succeeds");
46-
($res) = $ctx->capture_cmd(60, 'nix', 'log', $outpath);
51+
($res) = $ctx->capture_cmd(60, 'nix', '--store', $store_uri, 'log', $outpath);
4752
is($res, 0, "Reading the output's log succeeds");
48-
($res) = $ctx->capture_cmd(15, 'nix-store', '--delete', $outpath);
53+
($res) = $ctx->capture_cmd(15, 'nix-store', '--store', $store_uri, '--delete', $outpath);
4954
is($res, 0, "Deleting the notifications.nix output succeeded");
50-
($res) = $ctx->capture_cmd(60, 'nix-collect-garbage');
55+
($res) = $ctx->capture_cmd(60, 'nix-collect-garbage', '--store', $store_uri);
5156
is($res, 0, "Delete all the system's garbage");
52-
File::Path::rmtree($ctx->{central}{nix_log_dir});
57+
File::Path::rmtree($ctx->{builder}{nix_log_dir});
5358
};
5459

5560
subtest "Ensure substituting the job works, but reading the log fails" => sub {
5661
# Build the store path, with --max-jobs 0 to prevent builds
5762
my $outlink = $ctx->tmpdir . "/basic-canbesubstituted";
5863
my ($res);
59-
($res) = $ctx->capture_cmd(60, 'nix-build', $ctx->jobsdir . '/notifications.nix', '-A', 'canbesubstituted', '--max-jobs', '0', '--out-link', $outlink);
64+
($res) = $ctx->capture_cmd(60, 'nix-build', '--store', $store_uri, $ctx->jobsdir . '/notifications.nix', '-A', 'canbesubstituted', '--max-jobs', '0', '--out-link', $outlink);
6065
is($res, 0, "Building notifications.nix succeeded");
6166
my $outpath = readlink($outlink);
6267

6368
# Verify trying to read this path's log fails, since we substituted it
64-
($res) = $ctx->capture_cmd(60, 'nix', 'log', $outpath);
69+
($res) = $ctx->capture_cmd(60, 'nix', '--store', $store_uri, 'log', $outpath);
6570
isnt($res, 0, "Reading the deleted output's log fails");
6671

6772
# Delete the store path again and all of the store's garbage, ensuring
6873
# Hydra will try to build it.
6974
is(unlink($outlink), 1, "Deleting the GC root succeeds");
70-
($res) = $ctx->capture_cmd(15, 'nix-store', '--delete', $outpath);
75+
($res) = $ctx->capture_cmd(15, 'nix-store', '--store', $store_uri, '--delete', $outpath);
7176
is($res, 0, "Deleting the notifications.nix output succeeded");
72-
($res) = $ctx->capture_cmd(60, 'nix-collect-garbage');
77+
($res) = $ctx->capture_cmd(60, 'nix-collect-garbage', '--store', $store_uri);
7378
is($res, 0, "Delete all the system's garbage");
7479
};
7580

0 commit comments

Comments
 (0)