Skip to content

Commit

Permalink
startDaemon(): Detect if the daemon crashes before creating the socket
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Feb 18, 2025
1 parent 9427c02 commit 11c42cb
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tests/functional/common/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..."
fi

# Dont 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
return
fi
Expand All @@ -76,15 +76,19 @@ startDaemon() {
PATH=$DAEMON_PATH nix --extra-experimental-features 'nix-command' daemon &
_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
DAEMON_STARTED=1
break;
fi
if ! kill -0 "$_NIX_TEST_DAEMON_PID"; then
echo "daemon died unexpectedly" >&2
exit 1
fi
sleep 0.1
done
if [[ -z ${DAEMON_STARTED+x} ]]; then
fail "Didnt manage to start the daemon"
fail "Didn't manage to start the daemon"
fi
trap "killDaemon" EXIT
# Save for if daemon is killed
Expand All @@ -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 ..."
fi

# Dont 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
return
fi
Expand Down Expand Up @@ -219,7 +223,7 @@ assertStderr() {

needLocalStore() {
if [[ "$NIX_REMOTE" == "daemon" ]]; then
skipTest "Cant run through the daemon ($1)"
skipTest "Can't run through the daemon ($1)"
fi
}

Expand Down

0 comments on commit 11c42cb

Please sign in to comment.