-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add unit test for http-binary-cache #14266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
710f943
5911d76
dfc73fa
63d612a
d77c6e7
d25b602
1821522
c0b82ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,6 @@ | |
| nixpkgs-regression, | ||
| ... | ||
| }: | ||
|
|
||
| let | ||
| inherit (nixpkgs) lib; | ||
|
|
||
|
|
@@ -202,7 +201,6 @@ | |
| hostTarget = f hostTarget; | ||
| targetTarget = f targetTarget; | ||
| }; | ||
|
|
||
| in | ||
| args@{ | ||
| pkgs, | ||
|
|
@@ -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 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
|
@@ -555,7 +569,6 @@ | |
| pkgs, | ||
| getStdenv ? pkgs: pkgs.stdenv, | ||
| }: | ||
|
|
||
| let | ||
| packageSets = packageSetsFor { inherit getStdenv pkgs; }; | ||
| in | ||
|
|
||
| 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 { | ||
|
|
||
|
|
@@ -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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe due to sandboxing?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 am developing on a Linux machine so I couldn't dive deeper and the edit-cycle with GHA is quite slow. 🙏
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to add |
||
|
|
||
| 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 | ||
There was a problem hiding this comment.
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
checkin theflake.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