2023-09-05 01:15:32 +03:00
|
|
|
#include <regex>
|
2024-06-12 17:02:20 +03:00
|
|
|
#include <thread>
|
2023-09-05 01:15:32 +03:00
|
|
|
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include "worker-protocol.hh"
|
2024-05-23 23:40:05 +03:00
|
|
|
#include "worker-protocol-connection.hh"
|
2023-09-05 01:15:32 +03:00
|
|
|
#include "worker-protocol-impl.hh"
|
|
|
|
#include "derived-path.hh"
|
2023-09-26 21:44:15 +03:00
|
|
|
#include "build-result.hh"
|
2023-10-05 06:27:50 +03:00
|
|
|
#include "tests/protocol.hh"
|
|
|
|
#include "tests/characterization.hh"
|
2023-09-05 01:15:32 +03:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2023-10-05 06:27:50 +03:00
|
|
|
const char workerProtoDir[] = "worker-protocol";
|
2023-09-05 01:15:32 +03:00
|
|
|
|
2022-03-25 06:40:49 +02:00
|
|
|
struct WorkerProtoTest : VersionedProtoTest<WorkerProto, workerProtoDir>
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* For serializers that don't care about the minimum version, we
|
2024-05-23 23:40:05 +03:00
|
|
|
* used the oldest one: 1.10.
|
2022-03-25 06:40:49 +02:00
|
|
|
*/
|
2024-05-23 23:40:05 +03:00
|
|
|
WorkerProto::Version defaultVersion = 1 << 8 | 10;
|
2022-03-25 06:40:49 +02:00
|
|
|
};
|
2023-09-05 01:15:32 +03:00
|
|
|
|
2022-03-25 06:40:49 +02:00
|
|
|
|
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2023-10-05 06:27:50 +03:00
|
|
|
WorkerProtoTest,
|
2023-09-05 01:15:32 +03:00
|
|
|
string,
|
|
|
|
"string",
|
2022-03-25 06:40:49 +02:00
|
|
|
defaultVersion,
|
2023-09-05 01:15:32 +03:00
|
|
|
(std::tuple<std::string, std::string, std::string, std::string, std::string> {
|
|
|
|
"",
|
|
|
|
"hi",
|
|
|
|
"white rabbit",
|
|
|
|
"大白兔",
|
|
|
|
"oh no \0\0\0 what was that!",
|
|
|
|
}))
|
|
|
|
|
2022-03-25 06:40:49 +02:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2023-10-05 06:27:50 +03:00
|
|
|
WorkerProtoTest,
|
2023-09-05 01:15:32 +03:00
|
|
|
storePath,
|
|
|
|
"store-path",
|
2022-03-25 06:40:49 +02:00
|
|
|
defaultVersion,
|
2023-09-05 01:15:32 +03:00
|
|
|
(std::tuple<StorePath, StorePath> {
|
|
|
|
StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo" },
|
|
|
|
StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo-bar" },
|
|
|
|
}))
|
|
|
|
|
2022-03-25 06:40:49 +02:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2023-10-05 06:27:50 +03:00
|
|
|
WorkerProtoTest,
|
2023-09-05 01:15:32 +03:00
|
|
|
contentAddress,
|
|
|
|
"content-address",
|
2022-03-25 06:40:49 +02:00
|
|
|
defaultVersion,
|
2023-09-05 01:15:32 +03:00
|
|
|
(std::tuple<ContentAddress, ContentAddress, ContentAddress> {
|
|
|
|
ContentAddress {
|
|
|
|
.method = TextIngestionMethod {},
|
2023-11-28 15:20:27 +02:00
|
|
|
.hash = hashString(HashAlgorithm::SHA256, "Derive(...)"),
|
2023-09-05 01:15:32 +03:00
|
|
|
},
|
|
|
|
ContentAddress {
|
|
|
|
.method = FileIngestionMethod::Flat,
|
2023-11-28 15:20:27 +02:00
|
|
|
.hash = hashString(HashAlgorithm::SHA1, "blob blob..."),
|
2023-09-05 01:15:32 +03:00
|
|
|
},
|
|
|
|
ContentAddress {
|
|
|
|
.method = FileIngestionMethod::Recursive,
|
2023-11-28 15:20:27 +02:00
|
|
|
.hash = hashString(HashAlgorithm::SHA256, "(...)"),
|
2023-09-05 01:15:32 +03:00
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
2022-03-25 06:40:49 +02:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2023-10-05 06:27:50 +03:00
|
|
|
WorkerProtoTest,
|
2023-05-26 21:48:11 +03:00
|
|
|
derivedPath_1_29,
|
|
|
|
"derived-path-1.29",
|
|
|
|
1 << 8 | 29,
|
|
|
|
(std::tuple<DerivedPath, DerivedPath, DerivedPath> {
|
|
|
|
DerivedPath::Opaque {
|
|
|
|
.path = StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo" },
|
|
|
|
},
|
|
|
|
DerivedPath::Built {
|
|
|
|
.drvPath = makeConstantStorePathRef(StorePath {
|
|
|
|
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
|
|
|
|
}),
|
|
|
|
.outputs = OutputsSpec::All { },
|
|
|
|
},
|
|
|
|
DerivedPath::Built {
|
|
|
|
.drvPath = makeConstantStorePathRef(StorePath {
|
|
|
|
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
|
|
|
|
}),
|
|
|
|
.outputs = OutputsSpec::Names { "x", "y" },
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
|
|
|
WorkerProtoTest,
|
|
|
|
derivedPath_1_30,
|
|
|
|
"derived-path-1.30",
|
|
|
|
1 << 8 | 30,
|
2023-10-16 08:45:06 +03:00
|
|
|
(std::tuple<DerivedPath, DerivedPath, DerivedPath, DerivedPath> {
|
2023-09-05 01:15:32 +03:00
|
|
|
DerivedPath::Opaque {
|
|
|
|
.path = StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo" },
|
|
|
|
},
|
2023-10-16 08:45:06 +03:00
|
|
|
DerivedPath::Opaque {
|
|
|
|
.path = StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv" },
|
|
|
|
},
|
|
|
|
DerivedPath::Built {
|
|
|
|
.drvPath = makeConstantStorePathRef(StorePath {
|
|
|
|
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
|
|
|
|
}),
|
|
|
|
.outputs = OutputsSpec::All { },
|
|
|
|
},
|
2023-09-05 01:15:32 +03:00
|
|
|
DerivedPath::Built {
|
|
|
|
.drvPath = makeConstantStorePathRef(StorePath {
|
|
|
|
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
|
|
|
|
}),
|
|
|
|
.outputs = OutputsSpec::Names { "x", "y" },
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
2022-03-25 06:40:49 +02:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2023-10-05 06:27:50 +03:00
|
|
|
WorkerProtoTest,
|
2023-09-26 21:44:15 +03:00
|
|
|
drvOutput,
|
|
|
|
"drv-output",
|
2022-03-25 06:40:49 +02:00
|
|
|
defaultVersion,
|
2023-09-26 21:44:15 +03:00
|
|
|
(std::tuple<DrvOutput, DrvOutput> {
|
|
|
|
{
|
|
|
|
.drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
|
|
|
|
.outputName = "baz",
|
|
|
|
},
|
|
|
|
DrvOutput {
|
|
|
|
.drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
|
|
|
|
.outputName = "quux",
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
2022-03-25 06:40:49 +02:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2023-10-05 06:27:50 +03:00
|
|
|
WorkerProtoTest,
|
2023-09-26 21:44:15 +03:00
|
|
|
realisation,
|
|
|
|
"realisation",
|
2022-03-25 06:40:49 +02:00
|
|
|
defaultVersion,
|
2023-09-26 21:44:15 +03:00
|
|
|
(std::tuple<Realisation, Realisation> {
|
|
|
|
Realisation {
|
|
|
|
.id = DrvOutput {
|
|
|
|
.drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
|
|
|
|
.outputName = "baz",
|
|
|
|
},
|
|
|
|
.outPath = StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo" },
|
|
|
|
.signatures = { "asdf", "qwer" },
|
|
|
|
},
|
|
|
|
Realisation {
|
|
|
|
.id = {
|
|
|
|
.drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
|
|
|
|
.outputName = "baz",
|
|
|
|
},
|
|
|
|
.outPath = StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo" },
|
|
|
|
.signatures = { "asdf", "qwer" },
|
|
|
|
.dependentRealisations = {
|
|
|
|
{
|
|
|
|
DrvOutput {
|
|
|
|
.drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
|
|
|
|
.outputName = "quux",
|
|
|
|
},
|
|
|
|
StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo" },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
2022-03-25 06:40:49 +02:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2023-10-05 06:27:50 +03:00
|
|
|
WorkerProtoTest,
|
2021-02-28 20:42:46 +02:00
|
|
|
buildResult_1_27,
|
|
|
|
"build-result-1.27",
|
|
|
|
1 << 8 | 27,
|
|
|
|
({
|
|
|
|
using namespace std::literals::chrono_literals;
|
|
|
|
std::tuple<BuildResult, BuildResult, BuildResult> t {
|
|
|
|
BuildResult {
|
|
|
|
.status = BuildResult::OutputRejected,
|
|
|
|
.errorMsg = "no idea why",
|
|
|
|
},
|
|
|
|
BuildResult {
|
|
|
|
.status = BuildResult::NotDeterministic,
|
|
|
|
.errorMsg = "no idea why",
|
|
|
|
},
|
|
|
|
BuildResult {
|
|
|
|
.status = BuildResult::Built,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
t;
|
|
|
|
}))
|
|
|
|
|
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
|
|
|
WorkerProtoTest,
|
|
|
|
buildResult_1_28,
|
|
|
|
"build-result-1.28",
|
|
|
|
1 << 8 | 28,
|
|
|
|
({
|
|
|
|
using namespace std::literals::chrono_literals;
|
|
|
|
std::tuple<BuildResult, BuildResult, BuildResult> t {
|
|
|
|
BuildResult {
|
|
|
|
.status = BuildResult::OutputRejected,
|
|
|
|
.errorMsg = "no idea why",
|
|
|
|
},
|
|
|
|
BuildResult {
|
|
|
|
.status = BuildResult::NotDeterministic,
|
|
|
|
.errorMsg = "no idea why",
|
|
|
|
},
|
|
|
|
BuildResult {
|
|
|
|
.status = BuildResult::Built,
|
|
|
|
.builtOutputs = {
|
|
|
|
{
|
|
|
|
"foo",
|
|
|
|
{
|
|
|
|
.id = DrvOutput {
|
|
|
|
.drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
|
|
|
|
.outputName = "foo",
|
|
|
|
},
|
|
|
|
.outPath = StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo" },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"bar",
|
|
|
|
{
|
|
|
|
.id = DrvOutput {
|
|
|
|
.drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
|
|
|
|
.outputName = "bar",
|
|
|
|
},
|
|
|
|
.outPath = StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar" },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
t;
|
|
|
|
}))
|
|
|
|
|
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
|
|
|
WorkerProtoTest,
|
|
|
|
buildResult_1_29,
|
|
|
|
"build-result-1.29",
|
|
|
|
1 << 8 | 29,
|
2023-09-26 21:44:15 +03:00
|
|
|
({
|
|
|
|
using namespace std::literals::chrono_literals;
|
2023-10-05 00:36:49 +03:00
|
|
|
std::tuple<BuildResult, BuildResult, BuildResult> t {
|
2023-09-26 21:44:15 +03:00
|
|
|
BuildResult {
|
|
|
|
.status = BuildResult::OutputRejected,
|
|
|
|
.errorMsg = "no idea why",
|
|
|
|
},
|
|
|
|
BuildResult {
|
|
|
|
.status = BuildResult::NotDeterministic,
|
|
|
|
.errorMsg = "no idea why",
|
|
|
|
.timesBuilt = 3,
|
|
|
|
.isNonDeterministic = true,
|
|
|
|
.startTime = 30,
|
|
|
|
.stopTime = 50,
|
|
|
|
},
|
|
|
|
BuildResult {
|
|
|
|
.status = BuildResult::Built,
|
|
|
|
.timesBuilt = 1,
|
|
|
|
.builtOutputs = {
|
|
|
|
{
|
|
|
|
"foo",
|
|
|
|
{
|
|
|
|
.id = DrvOutput {
|
|
|
|
.drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
|
|
|
|
.outputName = "foo",
|
|
|
|
},
|
|
|
|
.outPath = StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo" },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"bar",
|
|
|
|
{
|
|
|
|
.id = DrvOutput {
|
|
|
|
.drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
|
|
|
|
.outputName = "bar",
|
|
|
|
},
|
|
|
|
.outPath = StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar" },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.startTime = 30,
|
|
|
|
.stopTime = 50,
|
2023-12-13 23:37:17 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
t;
|
|
|
|
}))
|
|
|
|
|
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
|
|
|
WorkerProtoTest,
|
|
|
|
buildResult_1_37,
|
|
|
|
"build-result-1.37",
|
|
|
|
1 << 8 | 37,
|
|
|
|
({
|
|
|
|
using namespace std::literals::chrono_literals;
|
|
|
|
std::tuple<BuildResult, BuildResult, BuildResult> t {
|
|
|
|
BuildResult {
|
|
|
|
.status = BuildResult::OutputRejected,
|
|
|
|
.errorMsg = "no idea why",
|
|
|
|
},
|
|
|
|
BuildResult {
|
|
|
|
.status = BuildResult::NotDeterministic,
|
|
|
|
.errorMsg = "no idea why",
|
|
|
|
.timesBuilt = 3,
|
|
|
|
.isNonDeterministic = true,
|
|
|
|
.startTime = 30,
|
|
|
|
.stopTime = 50,
|
|
|
|
},
|
|
|
|
BuildResult {
|
|
|
|
.status = BuildResult::Built,
|
|
|
|
.timesBuilt = 1,
|
|
|
|
.builtOutputs = {
|
|
|
|
{
|
|
|
|
"foo",
|
|
|
|
{
|
|
|
|
.id = DrvOutput {
|
|
|
|
.drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
|
|
|
|
.outputName = "foo",
|
|
|
|
},
|
|
|
|
.outPath = StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo" },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"bar",
|
|
|
|
{
|
|
|
|
.id = DrvOutput {
|
|
|
|
.drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
|
|
|
|
.outputName = "bar",
|
|
|
|
},
|
|
|
|
.outPath = StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar" },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.startTime = 30,
|
|
|
|
.stopTime = 50,
|
|
|
|
.cpuUser = std::chrono::microseconds(500s),
|
|
|
|
.cpuSystem = std::chrono::microseconds(604s),
|
2023-10-05 00:36:49 +03:00
|
|
|
},
|
2023-09-26 21:44:15 +03:00
|
|
|
};
|
|
|
|
t;
|
|
|
|
}))
|
|
|
|
|
2022-03-25 06:40:49 +02:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2023-10-05 06:27:50 +03:00
|
|
|
WorkerProtoTest,
|
2021-02-28 20:42:46 +02:00
|
|
|
keyedBuildResult_1_29,
|
|
|
|
"keyed-build-result-1.29",
|
|
|
|
1 << 8 | 29,
|
2023-09-26 21:44:15 +03:00
|
|
|
({
|
|
|
|
using namespace std::literals::chrono_literals;
|
|
|
|
std::tuple<KeyedBuildResult, KeyedBuildResult/*, KeyedBuildResult*/> t {
|
|
|
|
KeyedBuildResult {
|
|
|
|
{
|
|
|
|
.status = KeyedBuildResult::OutputRejected,
|
|
|
|
.errorMsg = "no idea why",
|
|
|
|
},
|
|
|
|
/* .path = */ DerivedPath::Opaque {
|
|
|
|
StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-xxx" },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
KeyedBuildResult {
|
|
|
|
{
|
|
|
|
.status = KeyedBuildResult::NotDeterministic,
|
|
|
|
.errorMsg = "no idea why",
|
|
|
|
.timesBuilt = 3,
|
|
|
|
.isNonDeterministic = true,
|
|
|
|
.startTime = 30,
|
|
|
|
.stopTime = 50,
|
|
|
|
},
|
|
|
|
/* .path = */ DerivedPath::Built {
|
|
|
|
.drvPath = makeConstantStorePathRef(StorePath {
|
|
|
|
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
|
|
|
|
}),
|
|
|
|
.outputs = OutputsSpec::Names { "out" },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
t;
|
|
|
|
}))
|
|
|
|
|
2023-04-18 00:13:44 +03:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
|
|
|
WorkerProtoTest,
|
|
|
|
unkeyedValidPathInfo_1_15,
|
|
|
|
"unkeyed-valid-path-info-1.15",
|
|
|
|
1 << 8 | 15,
|
|
|
|
(std::tuple<UnkeyedValidPathInfo, UnkeyedValidPathInfo> {
|
|
|
|
({
|
|
|
|
UnkeyedValidPathInfo info {
|
|
|
|
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
|
|
|
|
};
|
|
|
|
info.registrationTime = 23423;
|
|
|
|
info.narSize = 34878;
|
|
|
|
info;
|
|
|
|
}),
|
|
|
|
({
|
|
|
|
UnkeyedValidPathInfo info {
|
|
|
|
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
|
|
|
|
};
|
|
|
|
info.deriver = StorePath {
|
|
|
|
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
|
|
|
|
};
|
|
|
|
info.references = {
|
|
|
|
StorePath {
|
|
|
|
"g1w7hyyyy1w7hy3qg1w7hy3qgqqqqy3q-foo.drv",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
info.registrationTime = 23423;
|
|
|
|
info.narSize = 34878;
|
|
|
|
info;
|
|
|
|
}),
|
|
|
|
}))
|
|
|
|
|
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
|
|
|
WorkerProtoTest,
|
|
|
|
validPathInfo_1_15,
|
|
|
|
"valid-path-info-1.15",
|
|
|
|
1 << 8 | 15,
|
|
|
|
(std::tuple<ValidPathInfo, ValidPathInfo> {
|
|
|
|
({
|
|
|
|
ValidPathInfo info {
|
|
|
|
StorePath {
|
|
|
|
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",
|
|
|
|
},
|
|
|
|
UnkeyedValidPathInfo {
|
|
|
|
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
info.registrationTime = 23423;
|
|
|
|
info.narSize = 34878;
|
|
|
|
info;
|
|
|
|
}),
|
|
|
|
({
|
|
|
|
ValidPathInfo info {
|
|
|
|
StorePath {
|
|
|
|
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",
|
|
|
|
},
|
|
|
|
UnkeyedValidPathInfo {
|
|
|
|
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
info.deriver = StorePath {
|
|
|
|
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
|
|
|
|
};
|
|
|
|
info.references = {
|
|
|
|
// other reference
|
|
|
|
StorePath {
|
|
|
|
"g1w7hyyyy1w7hy3qg1w7hy3qgqqqqy3q-foo",
|
|
|
|
},
|
|
|
|
// self reference
|
|
|
|
StorePath {
|
|
|
|
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
info.registrationTime = 23423;
|
|
|
|
info.narSize = 34878;
|
|
|
|
info;
|
|
|
|
}),
|
|
|
|
}))
|
|
|
|
|
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
|
|
|
WorkerProtoTest,
|
|
|
|
validPathInfo_1_16,
|
|
|
|
"valid-path-info-1.16",
|
|
|
|
1 << 8 | 16,
|
|
|
|
(std::tuple<ValidPathInfo, ValidPathInfo, ValidPathInfo> {
|
|
|
|
({
|
|
|
|
ValidPathInfo info {
|
|
|
|
StorePath {
|
|
|
|
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",
|
|
|
|
},
|
|
|
|
UnkeyedValidPathInfo {
|
|
|
|
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
info.registrationTime = 23423;
|
|
|
|
info.narSize = 34878;
|
|
|
|
info.ultimate = true;
|
|
|
|
info;
|
|
|
|
}),
|
|
|
|
({
|
|
|
|
ValidPathInfo info {
|
|
|
|
StorePath {
|
|
|
|
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",
|
|
|
|
},
|
|
|
|
UnkeyedValidPathInfo {
|
|
|
|
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
info.deriver = StorePath {
|
|
|
|
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
|
|
|
|
};
|
|
|
|
info.references = {
|
|
|
|
// other reference
|
|
|
|
StorePath {
|
|
|
|
"g1w7hyyyy1w7hy3qg1w7hy3qgqqqqy3q-foo",
|
|
|
|
},
|
|
|
|
// self reference
|
|
|
|
StorePath {
|
|
|
|
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
info.registrationTime = 23423;
|
|
|
|
info.narSize = 34878;
|
|
|
|
info.sigs = {
|
|
|
|
"fake-sig-1",
|
|
|
|
"fake-sig-2",
|
|
|
|
},
|
|
|
|
info;
|
|
|
|
}),
|
|
|
|
({
|
|
|
|
ValidPathInfo info {
|
|
|
|
*LibStoreTest::store,
|
|
|
|
"foo",
|
|
|
|
FixedOutputInfo {
|
|
|
|
.method = FileIngestionMethod::Recursive,
|
2023-11-28 15:20:27 +02:00
|
|
|
.hash = hashString(HashAlgorithm::SHA256, "(...)"),
|
2023-04-18 00:13:44 +03:00
|
|
|
.references = {
|
|
|
|
.others = {
|
|
|
|
StorePath {
|
|
|
|
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.self = true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
|
|
|
|
};
|
|
|
|
info.registrationTime = 23423;
|
|
|
|
info.narSize = 34878;
|
|
|
|
info;
|
|
|
|
}),
|
|
|
|
}))
|
|
|
|
|
2024-05-27 07:18:58 +03:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
|
|
|
WorkerProtoTest,
|
|
|
|
buildMode,
|
|
|
|
"build-mode",
|
|
|
|
defaultVersion,
|
|
|
|
(std::tuple<BuildMode, BuildMode, BuildMode> {
|
|
|
|
bmNormal,
|
|
|
|
bmRepair,
|
|
|
|
bmCheck,
|
|
|
|
}))
|
|
|
|
|
2022-03-25 06:40:49 +02:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2023-10-05 06:27:50 +03:00
|
|
|
WorkerProtoTest,
|
2023-09-26 21:44:15 +03:00
|
|
|
optionalTrustedFlag,
|
|
|
|
"optional-trusted-flag",
|
2022-03-25 06:40:49 +02:00
|
|
|
defaultVersion,
|
2023-09-26 21:44:15 +03:00
|
|
|
(std::tuple<std::optional<TrustedFlag>, std::optional<TrustedFlag>, std::optional<TrustedFlag>> {
|
|
|
|
std::nullopt,
|
|
|
|
std::optional { Trusted },
|
|
|
|
std::optional { NotTrusted },
|
|
|
|
}))
|
|
|
|
|
2022-03-25 06:40:49 +02:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2023-10-05 06:27:50 +03:00
|
|
|
WorkerProtoTest,
|
2023-09-26 21:44:15 +03:00
|
|
|
vector,
|
|
|
|
"vector",
|
2022-03-25 06:40:49 +02:00
|
|
|
defaultVersion,
|
2023-09-26 21:44:15 +03:00
|
|
|
(std::tuple<std::vector<std::string>, std::vector<std::string>, std::vector<std::string>, std::vector<std::vector<std::string>>> {
|
|
|
|
{ },
|
|
|
|
{ "" },
|
|
|
|
{ "", "foo", "bar" },
|
|
|
|
{ {}, { "" }, { "", "1", "2" } },
|
|
|
|
}))
|
|
|
|
|
2022-03-25 06:40:49 +02:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2023-10-05 06:27:50 +03:00
|
|
|
WorkerProtoTest,
|
2023-09-26 21:44:15 +03:00
|
|
|
set,
|
|
|
|
"set",
|
2022-03-25 06:40:49 +02:00
|
|
|
defaultVersion,
|
2023-09-26 21:44:15 +03:00
|
|
|
(std::tuple<std::set<std::string>, std::set<std::string>, std::set<std::string>, std::set<std::set<std::string>>> {
|
|
|
|
{ },
|
|
|
|
{ "" },
|
|
|
|
{ "", "foo", "bar" },
|
|
|
|
{ {}, { "" }, { "", "1", "2" } },
|
|
|
|
}))
|
|
|
|
|
2022-03-25 06:40:49 +02:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2023-10-05 06:27:50 +03:00
|
|
|
WorkerProtoTest,
|
2023-09-26 21:44:15 +03:00
|
|
|
optionalStorePath,
|
|
|
|
"optional-store-path",
|
2022-03-25 06:40:49 +02:00
|
|
|
defaultVersion,
|
2023-09-26 21:44:15 +03:00
|
|
|
(std::tuple<std::optional<StorePath>, std::optional<StorePath>> {
|
|
|
|
std::nullopt,
|
|
|
|
std::optional {
|
|
|
|
StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo-bar" },
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
2022-03-25 06:40:49 +02:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2023-10-05 06:27:50 +03:00
|
|
|
WorkerProtoTest,
|
2023-09-26 21:44:15 +03:00
|
|
|
optionalContentAddress,
|
|
|
|
"optional-content-address",
|
2022-03-25 06:40:49 +02:00
|
|
|
defaultVersion,
|
2023-09-26 21:44:15 +03:00
|
|
|
(std::tuple<std::optional<ContentAddress>, std::optional<ContentAddress>> {
|
|
|
|
std::nullopt,
|
|
|
|
std::optional {
|
|
|
|
ContentAddress {
|
|
|
|
.method = FileIngestionMethod::Flat,
|
2023-11-28 15:20:27 +02:00
|
|
|
.hash = hashString(HashAlgorithm::SHA1, "blob blob..."),
|
2023-09-26 21:44:15 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
2024-05-23 23:40:05 +03:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
|
|
|
WorkerProtoTest,
|
|
|
|
clientHandshakeInfo_1_30,
|
|
|
|
"client-handshake-info_1_30",
|
|
|
|
1 << 8 | 30,
|
|
|
|
(std::tuple<WorkerProto::ClientHandshakeInfo> {
|
|
|
|
{},
|
|
|
|
}))
|
|
|
|
|
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
|
|
|
WorkerProtoTest,
|
|
|
|
clientHandshakeInfo_1_33,
|
|
|
|
"client-handshake-info_1_33",
|
|
|
|
1 << 8 | 33,
|
|
|
|
(std::tuple<WorkerProto::ClientHandshakeInfo, WorkerProto::ClientHandshakeInfo> {
|
|
|
|
{
|
|
|
|
.daemonNixVersion = std::optional { "foo" },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.daemonNixVersion = std::optional { "bar" },
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
|
|
|
WorkerProtoTest,
|
|
|
|
clientHandshakeInfo_1_35,
|
|
|
|
"client-handshake-info_1_35",
|
|
|
|
1 << 8 | 35,
|
|
|
|
(std::tuple<WorkerProto::ClientHandshakeInfo, WorkerProto::ClientHandshakeInfo> {
|
|
|
|
{
|
|
|
|
.daemonNixVersion = std::optional { "foo" },
|
|
|
|
.remoteTrustsUs = std::optional { NotTrusted },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.daemonNixVersion = std::optional { "bar" },
|
|
|
|
.remoteTrustsUs = std::optional { Trusted },
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
|
|
|
TEST_F(WorkerProtoTest, handshake_log)
|
|
|
|
{
|
|
|
|
CharacterizationTest::writeTest("handshake-to-client", [&]() -> std::string {
|
|
|
|
StringSink toClientLog;
|
|
|
|
|
|
|
|
Pipe toClient, toServer;
|
|
|
|
toClient.create();
|
|
|
|
toServer.create();
|
|
|
|
|
|
|
|
WorkerProto::Version clientResult;
|
|
|
|
|
|
|
|
auto thread = std::thread([&]() {
|
|
|
|
FdSink out { toServer.writeSide.get() };
|
|
|
|
FdSource in0 { toClient.readSide.get() };
|
|
|
|
TeeSource in { in0, toClientLog };
|
|
|
|
clientResult = WorkerProto::BasicClientConnection::handshake(
|
|
|
|
out, in, defaultVersion);
|
|
|
|
});
|
|
|
|
|
|
|
|
{
|
|
|
|
FdSink out { toClient.writeSide.get() };
|
|
|
|
FdSource in { toServer.readSide.get() };
|
|
|
|
WorkerProto::BasicServerConnection::handshake(
|
|
|
|
out, in, defaultVersion);
|
|
|
|
};
|
|
|
|
|
|
|
|
thread.join();
|
|
|
|
|
|
|
|
return std::move(toClientLog.s);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Has to be a `BufferedSink` for handshake.
|
|
|
|
struct NullBufferedSink : BufferedSink {
|
|
|
|
void writeUnbuffered(std::string_view data) override { }
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(WorkerProtoTest, handshake_client_replay)
|
|
|
|
{
|
|
|
|
CharacterizationTest::readTest("handshake-to-client", [&](std::string toClientLog) {
|
|
|
|
NullBufferedSink nullSink;
|
|
|
|
|
|
|
|
StringSource in { toClientLog };
|
|
|
|
auto clientResult = WorkerProto::BasicClientConnection::handshake(
|
|
|
|
nullSink, in, defaultVersion);
|
|
|
|
|
|
|
|
EXPECT_EQ(clientResult, defaultVersion);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WorkerProtoTest, handshake_client_truncated_replay_throws)
|
|
|
|
{
|
|
|
|
CharacterizationTest::readTest("handshake-to-client", [&](std::string toClientLog) {
|
|
|
|
for (size_t len = 0; len < toClientLog.size(); ++len) {
|
|
|
|
NullBufferedSink nullSink;
|
|
|
|
StringSource in {
|
|
|
|
// truncate
|
|
|
|
toClientLog.substr(0, len)
|
|
|
|
};
|
|
|
|
if (len < 8) {
|
|
|
|
EXPECT_THROW(
|
|
|
|
WorkerProto::BasicClientConnection::handshake(
|
|
|
|
nullSink, in, defaultVersion),
|
|
|
|
EndOfFile);
|
|
|
|
} else {
|
|
|
|
// Not sure why cannot keep on checking for `EndOfFile`.
|
|
|
|
EXPECT_THROW(
|
|
|
|
WorkerProto::BasicClientConnection::handshake(
|
|
|
|
nullSink, in, defaultVersion),
|
|
|
|
Error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WorkerProtoTest, handshake_client_corrupted_throws)
|
|
|
|
{
|
|
|
|
CharacterizationTest::readTest("handshake-to-client", [&](const std::string toClientLog) {
|
|
|
|
for (size_t idx = 0; idx < toClientLog.size(); ++idx) {
|
|
|
|
// corrupt a copy
|
|
|
|
std::string toClientLogCorrupt = toClientLog;
|
|
|
|
toClientLogCorrupt[idx] *= 4;
|
|
|
|
++toClientLogCorrupt[idx];
|
|
|
|
|
|
|
|
NullBufferedSink nullSink;
|
|
|
|
StringSource in { toClientLogCorrupt };
|
|
|
|
|
|
|
|
if (idx < 4 || idx == 9) {
|
|
|
|
// magic bytes don't match
|
|
|
|
EXPECT_THROW(
|
|
|
|
WorkerProto::BasicClientConnection::handshake(
|
|
|
|
nullSink, in, defaultVersion),
|
|
|
|
Error);
|
|
|
|
} else if (idx < 8 || idx >= 12) {
|
|
|
|
// Number out of bounds
|
|
|
|
EXPECT_THROW(
|
|
|
|
WorkerProto::BasicClientConnection::handshake(
|
|
|
|
nullSink, in, defaultVersion),
|
|
|
|
SerialisationError);
|
|
|
|
} else {
|
|
|
|
auto ver = WorkerProto::BasicClientConnection::handshake(
|
|
|
|
nullSink, in, defaultVersion);
|
|
|
|
// `std::min` of this and the other version saves us
|
|
|
|
EXPECT_EQ(ver, defaultVersion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-09-05 01:15:32 +03:00
|
|
|
}
|