mirror of
https://github.com/NixOS/nix
synced 2025-06-24 18:01:16 +02:00
startDaemon(): Detect if the daemon crashes before creating the socket
This avoids timeouts like those seen in
3735812034
.
This commit is contained in:
parent
9427c028ec
commit
11c42cb2e1
1 changed files with 9 additions and 5 deletions
|
@ -67,7 +67,7 @@ startDaemon() {
|
||||||
die "startDaemon: not supported when testing on NixOS. Is it really needed? If so add conditionals; e.g. if ! isTestOnNixOS; then ..."
|
die "startDaemon: not supported when testing on NixOS. Is it really needed? If so add conditionals; e.g. if ! isTestOnNixOS; then ..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Don’t start the daemon twice, as this would just make it loop indefinitely
|
# Don't start the daemon twice, as this would just make it loop indefinitely.
|
||||||
if [[ "${_NIX_TEST_DAEMON_PID-}" != '' ]]; then
|
if [[ "${_NIX_TEST_DAEMON_PID-}" != '' ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
@ -76,15 +76,19 @@ startDaemon() {
|
||||||
PATH=$DAEMON_PATH nix --extra-experimental-features 'nix-command' daemon &
|
PATH=$DAEMON_PATH nix --extra-experimental-features 'nix-command' daemon &
|
||||||
_NIX_TEST_DAEMON_PID=$!
|
_NIX_TEST_DAEMON_PID=$!
|
||||||
export _NIX_TEST_DAEMON_PID
|
export _NIX_TEST_DAEMON_PID
|
||||||
for ((i = 0; i < 300; i++)); do
|
for ((i = 0; i < 60; i++)); do
|
||||||
if [[ -S $NIX_DAEMON_SOCKET_PATH ]]; then
|
if [[ -S $NIX_DAEMON_SOCKET_PATH ]]; then
|
||||||
DAEMON_STARTED=1
|
DAEMON_STARTED=1
|
||||||
break;
|
break;
|
||||||
fi
|
fi
|
||||||
|
if ! kill -0 "$_NIX_TEST_DAEMON_PID"; then
|
||||||
|
echo "daemon died unexpectedly" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
done
|
done
|
||||||
if [[ -z ${DAEMON_STARTED+x} ]]; then
|
if [[ -z ${DAEMON_STARTED+x} ]]; then
|
||||||
fail "Didn’t manage to start the daemon"
|
fail "Didn't manage to start the daemon"
|
||||||
fi
|
fi
|
||||||
trap "killDaemon" EXIT
|
trap "killDaemon" EXIT
|
||||||
# Save for if daemon is killed
|
# Save for if daemon is killed
|
||||||
|
@ -97,7 +101,7 @@ killDaemon() {
|
||||||
die "killDaemon: not supported when testing on NixOS. Is it really needed? If so add conditionals; e.g. if ! isTestOnNixOS; then ..."
|
die "killDaemon: not supported when testing on NixOS. Is it really needed? If so add conditionals; e.g. if ! isTestOnNixOS; then ..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Don’t fail trying to stop a non-existant daemon twice
|
# Don't fail trying to stop a non-existant daemon twice.
|
||||||
if [[ "${_NIX_TEST_DAEMON_PID-}" == '' ]]; then
|
if [[ "${_NIX_TEST_DAEMON_PID-}" == '' ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
@ -219,7 +223,7 @@ assertStderr() {
|
||||||
|
|
||||||
needLocalStore() {
|
needLocalStore() {
|
||||||
if [[ "$NIX_REMOTE" == "daemon" ]]; then
|
if [[ "$NIX_REMOTE" == "daemon" ]]; then
|
||||||
skipTest "Can’t run through the daemon ($1)"
|
skipTest "Can't run through the daemon ($1)"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue