From d58b3274f9edc4bad9eb64cf958d48dfb1cc503c Mon Sep 17 00:00:00 2001 From: regnat Date: Wed, 28 Apr 2021 11:41:37 +0200 Subject: [PATCH 1/2] test: Don't generate a Nix conf in the makefile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The config is overriden by the `test_init` perl function, so it’s at best misleading to create a first one there --- t/Makefile.am | 2 -- 1 file changed, 2 deletions(-) diff --git a/t/Makefile.am b/t/Makefile.am index 358f3698..b8448fe8 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -34,7 +34,5 @@ dirs: touch data/hydra.conf mkdir -p nix mkdir -p nix/etc/nix - touch nix/etc/nix/nix.conf - echo "sandbox = false" >> nix/etc/nix/nix.conf mkdir -p nix/store mkdir -p nix/var From abff212d0631726502ce8a025e5ac5e4493828aa Mon Sep 17 00:00:00 2001 From: regnat Date: Wed, 28 Apr 2021 11:43:04 +0200 Subject: [PATCH 2/2] Use system-features from the Nix conf in the default machine file Fix #936 --- src/hydra-queue-runner/hydra-queue-runner.cc | 3 +- t/default-machine-file.t | 30 ++++++++++++++++++++ t/jobs/default-machine-file.nix | 9 ++++++ t/lib/Setup.pm | 1 + 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 t/default-machine-file.t create mode 100644 t/jobs/default-machine-file.nix diff --git a/src/hydra-queue-runner/hydra-queue-runner.cc b/src/hydra-queue-runner/hydra-queue-runner.cc index 3b9ae480..62eb572c 100644 --- a/src/hydra-queue-runner/hydra-queue-runner.cc +++ b/src/hydra-queue-runner/hydra-queue-runner.cc @@ -156,7 +156,8 @@ void State::monitorMachinesFile() if (machinesFiles.empty()) { parseMachines("localhost " + (settings.thisSystem == "x86_64-linux" ? "x86_64-linux,i686-linux" : settings.thisSystem.get()) - + " - " + std::to_string(settings.maxBuildJobs) + " 1"); + + " - " + std::to_string(settings.maxBuildJobs) + " 1 " + + concatStringsSep(",", settings.systemFeatures.get())); return; } diff --git a/t/default-machine-file.t b/t/default-machine-file.t new file mode 100644 index 00000000..01203a72 --- /dev/null +++ b/t/default-machine-file.t @@ -0,0 +1,30 @@ +use feature 'unicode_strings'; +use strict; +use Setup; + +my %ctx = test_init(); + +require Hydra::Schema; +require Hydra::Model::DB; + +use Test2::V0; + +my $db = Hydra::Model::DB->new; +hydra_setup($db); + +my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"}); + +my $jobset = createBaseJobset("default-machine-file", "default-machine-file.nix", $ctx{jobsdir}); + +ok(evalSucceeds($jobset), "Evaluating jobs/default-machine-file.nix should exit with return code 0"); +is(nrQueuedBuildsForJobset($jobset), 1, "Evaluating jobs/default-machine-file.nix should result in 1 build"); + +for my $build (queuedBuildsForJobset($jobset)) { + ok(runBuild($build), "Build '".$build->job."' from jobs/default-machine-file.nix should exit with code 0"); + my $newbuild = $db->resultset('Builds')->find($build->id); + is($newbuild->finished, 1, "Build '".$build->job."' from jobs/default-machine-file.nix should be finished."); + my $expected = $build->job eq "fails" ? 1 : $build->job =~ /with_failed/ ? 6 : 0; + is($newbuild->buildstatus, $expected, "Build '".$build->job."' from jobs/default-machine-file.nix should have buildstatus $expected."); +} + +done_testing; diff --git a/t/jobs/default-machine-file.nix b/t/jobs/default-machine-file.nix new file mode 100644 index 00000000..49647cb0 --- /dev/null +++ b/t/jobs/default-machine-file.nix @@ -0,0 +1,9 @@ +with import ./config.nix; +{ + requireExperimentalFeatures = + mkDerivation { + name = "empty-dir"; + builder = ./empty-dir-builder.sh; + requiredSystemFeatures = [ "test-system-feature" ]; + }; +} diff --git a/t/lib/Setup.pm b/t/lib/Setup.pm index b5236978..fc078ac5 100644 --- a/t/lib/Setup.pm +++ b/t/lib/Setup.pm @@ -48,6 +48,7 @@ sub test_init { my $nixconf = "$ENV{'NIX_CONF_DIR'}/nix.conf"; open(my $fh, '>', $nixconf) or die "Could not open file '$nixconf' $!"; print $fh "sandbox = false\n"; + print $fh "system-features = test-system-feature\n"; print $fh $opts{'nix_config'} || ""; close $fh;