Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ci/gha/tests/wrapper.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
{
nixFlake ? builtins.getFlake ("git+file://" + toString ../../..),
system ? builtins.currentSystem,
pkgs ? nixFlake.inputs.nixpkgs.legacyPackages.${system},
stdenv ? "stdenv",
componentTestsPrefix ? "",
withInstrumentation ? false,
}@args:
let
# Create a pkgs set with your httplib overlay applied.
pkgs = import nixFlake.inputs.nixpkgs {
inherit system;
overlays = [ nixFlake.overlays.internal ];
};
in
import ./. (
args
// {
inherit pkgs;
getStdenv = p: p.${stdenv};
withSanitizers = withInstrumentation;
withCoverage = withInstrumentation;
Comment on lines 1 to 21
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xokdvium you might want to review this change.
I am not sure why this wrapper.nix exists since the gha/tests file is also a check in the flake.nix.

I see you are the main author of it. The main problem was it was not propagating the overlays set in the flake.nix

Expand Down
21 changes: 17 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
nixpkgs-regression,
...
}:

let
inherit (nixpkgs) lib;

Expand Down Expand Up @@ -202,7 +201,6 @@
hostTarget = f hostTarget;
targetTarget = f targetTarget;
};

in
args@{
pkgs,
Expand Down Expand Up @@ -285,8 +283,24 @@
nixDependencies2 = packageSets.nixDependencies;

nix = final.nixComponents2.nix-cli;
};

# We need to support pkgconfig until https://github.com/NixOS/nixpkgs/pull/452456
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

httplib = prev.httplib.overrideAttrs (oldAttrs: {
nativeBuildInputs = (oldAttrs.nativeBuildInputs or [ ]) ++ [ prev.copyPkgconfigItems ];
pkgconfigItems = [
(prev.makePkgconfigItem rec {
name = "httplib";
version = oldAttrs.version;
cflags = [ "-I${variables.includedir}" ];
variables = rec {
prefix = placeholder "out";
includedir = "''${prefix}/include";
};
inherit (oldAttrs.meta) description;
})
];
});
};
in
{
overlays.internal = overlayFor (p: p.stdenv);
Expand Down Expand Up @@ -555,7 +569,6 @@
pkgs,
getStdenv ? pkgs: pkgs.stdenv,
}:

let
packageSets = packageSetsFor { inherit getStdenv pkgs; };
in
Expand Down
86 changes: 86 additions & 0 deletions src/libstore-tests/http-binary-cache-store.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <httplib.h>

#include "nix/store/http-binary-cache-store.hh"
#include "nix/store/path.hh"
#include "nix/util/url.hh"

namespace nix {

Expand Down Expand Up @@ -34,4 +38,86 @@ TEST(HttpBinaryCacheStore, constructConfigWithParamsAndUrlWithParams)
EXPECT_EQ(config.getReference().params, params);
}

struct ServerManager
{
httplib::Server & server;
std::thread & server_thread;

~ServerManager()
{
server.stop();
if (server_thread.joinable()) {
server_thread.join();
}
}
};

TEST(HttpBinaryCacheStore, NixCacheInfoBasicTest)
{
// FIXME: MacOS tests on Github actions were not able to bind to any port,
// it kept returning -1 for the bound port.
#if !defined(__linux__)
GTEST_SKIP() << "Skipping test on non-Linux platform due to unknown networking differences.";
#endif
Comment on lines +57 to +61
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ericson2314 I couldn't figure out why but the MacOS tests were not letting me opening up a port.
I tried "localhost" if it was IPV6 only but that also failed...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe due to sandboxing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edolstra interesting; is the sandbox different on MacOS vs Linux for Nix for networking?
I would have thought localhost would always allowed.....

I am developing on a Linux machine so I couldn't dive deeper and the edit-cycle with GHA is quite slow.
This one was causing me to scratch my head... so if you have breadcrumbs I'd love to learn the root cause for edification.

🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to add __darwinAllowLocalNetworking
Might be worth adding irrespective of the change to match Linux.


httplib::Server server;
server.Get("/nix-cache-info", [](const httplib::Request &, httplib::Response & res) {
res.set_content(
"StoreDir: /nix/store\n"
"WantMassQuery: 1\n"
"Priority: 40\n",
"text/plain");
});
int port = server.bind_to_any_port("127.0.0.1");
ASSERT_GT(port, 0);

auto serverUrl = "127.0.0.1:" + std::to_string(port);
auto serverThread = std::thread([&server]() { server.listen_after_bind(); });
// Create the RAII guard object. Its destructor will handle cleanup.
ServerManager manager(server, serverThread);

auto config = std::make_shared<HttpBinaryCacheStoreConfig>("http", serverUrl, StoreConfig::Params{});
auto store = config->openStore().dynamic_pointer_cast<BinaryCacheStore>();
ASSERT_TRUE(store);

auto cacheInfo = store->getNixCacheInfo();
EXPECT_EQ(cacheInfo.value(), "StoreDir: /nix/store\nWantMassQuery: 1\nPriority: 40\n");
}

TEST(HttpBinaryCacheStore, UrlEncodingPlusSign)
{
// FIXME: MacOS tests on Github actions were not able to bind to any port,
// it kept returning -1 for the bound port.
#if !defined(__linux__)
GTEST_SKIP() << "Skipping test on non-Linux platform due to unknown networking differences.";
#endif

httplib::Server server;
const std::string drvNameWithPlus = "bqlpc40ak1qn45zmv44h8cqjx12hphzi-hello+plus-1.0.drv";
const std::string expectedLogPath = "/log/" + drvNameWithPlus;
server.Get(R"(/log/(.+))", [&](const httplib::Request & req, httplib::Response & res) {
if (req.path == expectedLogPath) {
res.set_content("correct", "text/plain");
res.status = 200;
} else {
res.status = 404;
res.set_content("Not Found: Path was decoded incorrectly.", "text/plain");
}
});
int port = server.bind_to_any_port("127.0.0.1");
ASSERT_GT(port, 0);

auto serverUrl = "127.0.0.1:" + std::to_string(port);
auto serverThread = std::thread([&server]() { server.listen_after_bind(); });
// Create the RAII guard object. Its destructor will handle cleanup.
ServerManager manager(server, serverThread);

auto config = std::make_shared<HttpBinaryCacheStoreConfig>("http", serverUrl, StoreConfig::Params{});
auto store = config->openStore().dynamic_pointer_cast<BinaryCacheStore>();
ASSERT_TRUE(store);

auto buildLog = store->getBuildLogExact(StorePath{drvNameWithPlus});
EXPECT_THAT(buildLog, testing::Optional(testing::Eq("correct")));
}

} // namespace nix
3 changes: 3 additions & 0 deletions src/libstore-tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ config_priv_h = configure_file(
gtest = dependency('gmock')
deps_private += gtest

httplib = dependency('httplib')
deps_private += httplib

subdir('nix-meson-build-support/common')

sources = files(
Expand Down
2 changes: 2 additions & 0 deletions src/libstore-tests/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

rapidcheck,
gtest,
httplib,
gbenchmark,
runCommand,

Expand Down Expand Up @@ -47,6 +48,7 @@ mkMesonExecutable (finalAttrs: {
sqlite
rapidcheck
gtest
httplib
]
++ lib.optionals withBenchmarks [
gbenchmark
Expand Down
Loading