Merge remote-tracking branch 'origin/test-daemon-everywhere'

This commit is contained in:
Eelco Dolstra 2021-07-28 21:57:50 +02:00
commit c5ade241f0
25 changed files with 105 additions and 15 deletions

View file

@ -1,5 +1,7 @@
source common.sh
needLocalStore "“--no-require-sigs” cant be used with the daemon"
# We can produce drvs directly into the binary cache
clearStore
clearCacheCache

View file

@ -3,7 +3,8 @@
# Regression test for https://github.com/NixOS/nix/issues/4858
source common.sh
sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf
requireDaemonNewerThan "2.4pre20210621"
# Get the output path of `rootCA`, and put some garbage instead
outPath="$(nix-build ./content-addressed.nix -A rootCA --no-out-link)"

View file

@ -1 +1,5 @@
source ../common.sh
sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf
restartDaemon

View file

@ -5,7 +5,7 @@
source common.sh
sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf
buggyNeedLocalStore "For some reason, this deadlocks with the daemon"
export NIX_TESTS_CA_BY_DEFAULT=1

View file

@ -1,5 +1,7 @@
source ./common.sh
requireDaemonNewerThan "2.4pre20210625"
sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf
export REMOTE_STORE_DIR="$TEST_ROOT/remote_store"

View file

@ -4,8 +4,6 @@
source common.sh
sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf
export NIX_TESTS_CA_BY_DEFAULT=1
cd ..

View file

@ -2,6 +2,8 @@
source common.sh
requireDaemonNewerThan "2.4pre20210626"
sed -i 's/experimental-features .*/& ca-derivations ca-references nix-command flakes/' "$NIX_CONF_DIR"/nix.conf
export NIX_TESTS_CA_BY_DEFAULT=1

View file

@ -2,6 +2,8 @@
source common.sh
requireDaemonNewerThan "2.4pre20210623"
sed -i 's/experimental-features .*/& ca-derivations ca-references nix-command flakes/' "$NIX_CONF_DIR"/nix.conf
export NIX_TESTS_CA_BY_DEFAULT=1

View file

@ -4,7 +4,7 @@
source common.sh
sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf
needLocalStore "“--no-require-sigs” cant be used with the daemon"
rm -rf $TEST_ROOT/binary_cache

View file

@ -1,5 +1,8 @@
source common.sh
# XXX: This shouldnt be, but #4813 cause this test to fail
buggyNeedLocalStore "see #4813"
checkBuildTempDirRemoved ()
{
buildDir=$(sed -n 's/CHECK_TMPDIR=//p' $1 | head -1)

View file

@ -1,5 +1,9 @@
set -e
if [[ -z "$COMMON_SH_SOURCED" ]]; then
COMMON_SH_SOURCED=1
export TEST_ROOT=$(realpath ${TMPDIR:-/tmp}/nix-test)/${TEST_NAME:-default}
export NIX_STORE_DIR
if ! NIX_STORE_DIR=$(readlink -f $TEST_ROOT/store 2> /dev/null); then
@ -45,6 +49,9 @@ export busybox="@sandbox_shell@"
export version=@PACKAGE_VERSION@
export system=@system@
export IMPURE_VAR1=foo
export IMPURE_VAR2=bar
cacheDir=$TEST_ROOT/binary-cache
readLink() {
@ -75,29 +82,57 @@ clearCacheCache() {
}
startDaemon() {
# Dont start the daemon twice, as this would just make it loop indefinitely
if [[ "$NIX_REMOTE" == daemon ]]; then
return
fi
# Start the daemon, wait for the socket to appear. !!!
# nix-daemon should have an option to fork into the background.
rm -f $NIX_STATE_DIR/daemon-socket/socket
rm -f $NIX_DAEMON_SOCKET_PATH
${NIX_DAEMON_COMMAND:-nix daemon} &
for ((i = 0; i < 30; i++)); do
if [ -e $NIX_DAEMON_SOCKET_PATH ]; then break; fi
if [[ -S $NIX_DAEMON_SOCKET_PATH ]]; then break; fi
sleep 1
done
pidDaemon=$!
trap "kill -9 $pidDaemon" EXIT
trap "killDaemon" EXIT
export NIX_REMOTE=daemon
}
killDaemon() {
kill -9 $pidDaemon
kill $pidDaemon
for i in {0.10}; do
kill -0 $pidDaemon || break
sleep 1
done
kill -9 $pidDaemon || true
wait $pidDaemon || true
trap "" EXIT
}
restartDaemon() {
[[ -z "${pidDaemon:-}" ]] && return 0
killDaemon
unset NIX_REMOTE
startDaemon
}
if [[ $(uname) == Linux ]] && [[ -L /proc/self/ns/user ]] && unshare --user true; then
_canUseSandbox=1
fi
isDaemonNewer () {
[[ -n "${NIX_DAEMON_PACKAGE:-}" ]] || return 0
local requiredVersion="$1"
local daemonVersion=$($NIX_DAEMON_PACKAGE/bin/nix-daemon --version | cut -d' ' -f3)
return [[ $(nix eval --expr "builtins.compareVersions ''$daemonVersion'' ''2.4''") -ge 0 ]]
}
requireDaemonNewerThan () {
isDaemonNewer "$1" || exit 99
}
canUseSandbox() {
if [[ ! $_canUseSandbox ]]; then
echo "Sandboxing not supported, skipping this test..."
@ -123,4 +158,22 @@ expect() {
[[ $res -eq $expected ]]
}
needLocalStore() {
if [[ "$NIX_REMOTE" == "daemon" ]]; then
echo "Cant run through the daemon ($1), skipping this test..."
return 99
fi
}
# Just to make it easy to find which tests should be fixed
buggyNeedLocalStore () {
needLocalStore
}
set -x
if [[ -n "${NIX_DAEMON_PACKAGE:-}" ]]; then
startDaemon
fi
fi # COMMON_SH_SOURCED

View file

@ -3,11 +3,14 @@
# Only run this if we have an older Nix available
# XXX: This assumes that the `daemon` package is older than the `client` one
if [[ -z "$NIX_DAEMON_PACKAGE" ]]; then
exit 0
exit 99
fi
source common.sh
killDaemon
unset NIX_REMOTE
# Fill the db using the older Nix
PATH_WITH_NEW_NIX="$PATH"
export PATH="$NIX_DAEMON_PACKAGE/bin:$PATH"

View file

@ -1,5 +1,7 @@
source common.sh
needLocalStore "--dump-db requires a local store"
clearStore
path=$(nix-build dependencies.nix -o $TEST_ROOT/result)

View file

@ -1,5 +1,7 @@
source common.sh
requireDaemonNewerThan "2.4pre20210727"
eval_store=$TEST_ROOT/eval-store
clearStore

View file

@ -2,9 +2,6 @@ source common.sh
clearStore
export IMPURE_VAR1=foo
export IMPURE_VAR2=bar
path=$(nix-store -q $(nix-instantiate fixed.nix -A good.0))
echo 'testing bad...'

View file

@ -1,5 +1,7 @@
source common.sh
needLocalStore "“min-free” and “max-free” are daemon options"
clearStore
garbage1=$(nix store add-path --name garbage1 ./nar-access.sh)

View file

@ -23,6 +23,7 @@ substituters =
flake-registry = $TEST_ROOT/registry.json
show-trace = true
include nix.conf.extra
trusted-users = $(whoami)
EOF
cat > "$NIX_CONF_DIR"/nix.conf.extra <<EOF

View file

@ -1,5 +1,7 @@
source common.sh
needLocalStore "the sandbox only runs on the builder side, so it makes no sense to test it with the daemon"
clearStore
if ! canUseSandbox; then exit 99; fi

View file

@ -58,7 +58,7 @@ outPath2=$(nix-build $(nix-instantiate multiple-outputs.nix -A a.second) --no-ou
# Delete one of the outputs and rebuild it. This will cause a hash
# rewrite.
nix store delete $TEST_ROOT/result-second --ignore-liveness
env -u NIX_REMOTE nix store delete $TEST_ROOT/result-second --ignore-liveness
nix-build multiple-outputs.nix -A a.all -o $TEST_ROOT/result
[ "$(cat $TEST_ROOT/result-second/file)" = "second" ]
[ "$(cat $TEST_ROOT/result-second/link/file)" = "first" ]

View file

@ -26,7 +26,8 @@ if [ "$inode1" = "$inode3" ]; then
exit 1
fi
nix-store --optimise
# XXX: This should work through the daemon too
NIX_REMOTE="" nix-store --optimise
inode1="$(stat --format=%i $outPath1/foo)"
inode3="$(stat --format=%i $outPath3/foo)"

View file

@ -5,6 +5,9 @@ clearStore
rm -f $TEST_ROOT/result
export REMOTE_STORE=file:$TEST_ROOT/remote_store
echo 'require-sigs = false' >> $NIX_CONF_DIR/nix.conf
restartDaemon
# Build the dependencies and push them to the remote store
nix-build -o $TEST_ROOT/result dependencies.nix --post-build-hook $PWD/push-to-store.sh

View file

@ -1,5 +1,7 @@
source common.sh
needLocalStore "uses some low-level store manipulations that arent available through the daemon"
clearStore
max=500

View file

@ -1,5 +1,7 @@
source common.sh
needLocalStore "--repair needs a local store"
clearStore
path=$(nix-build dependencies.nix -o $TEST_ROOT/result)

View file

@ -1,5 +1,9 @@
source common.sh
# 27ce722638 required some incompatible changes to the nix file, so skip this
# tests for the older versions
requireDaemonNewerThan "2.4pre20210622"
clearStore
rm -f $TEST_ROOT/result

View file

@ -2,6 +2,8 @@
source common.sh
# XXX: This shouldnt be, but #4813 cause this test to fail
needLocalStore "see #4813"
set +e
messages=$(nix-build -Q timeout.nix -A infiniteLoop --timeout 2 2>&1)