Skip to content

Add unit test for http-binary-cache#14266

Open
fzakaria wants to merge 8 commits intoNixOS:masterfrom
fzakaria:fzakaria/issue-12910
Open

Add unit test for http-binary-cache#14266
fzakaria wants to merge 8 commits intoNixOS:masterfrom
fzakaria:fzakaria/issue-12910

Conversation

@fzakaria
Copy link
Contributor

Motivation

Add unit tests to validate http-binary-cache.
These were written to investigate #12910 unfortunately though after some research it turns out that '+' in the path is not encoded.

I am contributing the unit tests nonetheless since they might prove fruitful in the future to test other functionality of the http binary cache store.


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@github-actions github-actions bot added the store Issues and pull requests concerning the Nix store label Oct 15, 2025
Add unit tests to validate http-binary-cache.
These were written to investigate NixOS#12910 unfortunately though after some
research it turns out that '+' in the path is not encoded.

I am contributing the unit tests nonetheless since they might prove
fruitful in the future to test other functionality of the http binary
cache store.
@fzakaria fzakaria force-pushed the fzakaria/issue-12910 branch from acff068 to dfc73fa Compare October 16, 2025 02:28
Comment on lines 1 to 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;
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

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.

Comment on lines +57 to +61
// 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
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.

@Ericson2314
Copy link
Member

I am slightly apprehensive about adding deps such as these to the unit test suite, it feels a bit integration-test territory.

OTOH, it might be possible to adapt LocalBinaryCacheStore so it worked with any SourceAccessor FileSystemObjectSink, and then we could rig it up with the memory source accessor too?

@edolstra
Copy link
Member

In general, Nix tests should not listen on TCP ports because that doesn't work reliably unless the build runs in its own network namespace. And it opens a potential security issue if any process can connect to a server running inside the build.
Hence why we do this stuff in VM tests.

@fzakaria
Copy link
Contributor Author

@edolstra is that true for localhost as well?

also nix build is already in it's own network namespace I thought?

@fzakaria
Copy link
Contributor Author

Anyways, I found this unit test useful to investigate the binary cache issue but I see your points.
I learned a lot doing it (pkgconfig etc..) some more GoogleTest-isms. :)

I leave it to your best judgement (@edolstra , @edolstra etc..) on whether they want to accept it. 🙇

xokdvium added a commit to vlaci/nix that referenced this pull request Jan 18, 2026
This addresses the concerns with network isolation that have been raised
previously [1] by only running the tests by default in a network namespace.
This way all networks tests are independent of each other and do not bind
to ports in the host namespace.

This is much neater than doing these sorts of tests in functional suite.

[1]: NixOS#14266 (comment)
Mic92 pushed a commit to Mic92/nix-1 that referenced this pull request Jan 19, 2026
This addresses the concerns with network isolation that have been raised
previously [1] by only running the tests by default in a network namespace.
This way all networks tests are independent of each other and do not bind
to ports in the host namespace.

This is much neater than doing these sorts of tests in functional suite.

[1]: NixOS#14266 (comment)
Mic92 pushed a commit to Mic92/nix-1 that referenced this pull request Jan 20, 2026
This addresses the concerns with network isolation that have been raised
previously [1] by only running the tests by default in a network namespace.
This way all networks tests are independent of each other and do not bind
to ports in the host namespace.

This is much neater than doing these sorts of tests in functional suite.

[1]: NixOS#14266 (comment)
xokdvium added a commit to vlaci/nix that referenced this pull request Jan 24, 2026
This addresses the concerns with network isolation that have been raised
previously [1] by only running the tests by default in a network namespace.
This way all networks tests are independent of each other and do not bind
to ports in the host namespace.

This is much neater than doing these sorts of tests in functional suite.

[1]: NixOS#14266 (comment)
Mic92 pushed a commit to Mic92/nix-1 that referenced this pull request Jan 25, 2026
This addresses the concerns with network isolation that have been raised
previously [1] by only running the tests by default in a network namespace.
This way all networks tests are independent of each other and do not bind
to ports in the host namespace.

This is much neater than doing these sorts of tests in functional suite.

[1]: NixOS#14266 (comment)
Mic92 pushed a commit to Mic92/nix-1 that referenced this pull request Jan 25, 2026
This addresses the concerns with network isolation that have been raised
previously [1] by only running the tests by default in a network namespace.
This way all networks tests are independent of each other and do not bind
to ports in the host namespace.

This is much neater than doing these sorts of tests in functional suite.

[1]: NixOS#14266 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

store Issues and pull requests concerning the Nix store

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants