test: cover both of timesyncd's resolver paths

This checks that we resolve through resolved when it's running, and fall back
to getaddrinfo when it isn't.
This commit is contained in:
Clayton Craft
2026-08-15 13:12:50 -07:00
parent 8027ff6ecd
commit d52a693164
+71
View File
@@ -248,6 +248,19 @@ assert_timesyncd_state() {
return 1
}
assert_timesyncd_log() {
local cursor="${1:?}"
local match="${2:?}"
for _ in {0..29}; do
journalctl --sync
journalctl -q -u systemd-timesyncd.service --after-cursor="$(<"$cursor")" --grep "$match" >/dev/null && return 0
sleep .5
done
return 1
}
testcase_ntp() {
# timesyncd has ConditionVirtualization=!container by default; drop/mock that for testing
if systemd-detect-virt --container --quiet; then
@@ -409,6 +422,64 @@ EOF
rm -f /run/systemd/network/ntp99.*
}
teardown_timesyncd_resolve() {
set +eu
systemctl start systemd-resolved-varlink.socket
systemctl start systemd-resolved.service
rm -rf /run/systemd/system/systemd-timesyncd.service.d
systemctl daemon-reload
systemctl stop systemd-timesyncd
}
testcase_timesyncd_resolve() {
local cursor
if systemd-detect-virt -cq; then
echo "This test case requires a VM, skipping..."
return 0
fi
if ! command -v resolvectl >/dev/null; then
echo "This test requires systemd-resolved, skipping..."
return 0
fi
trap teardown_timesyncd_resolve RETURN
mkdir -p /run/systemd/system/systemd-timesyncd.service.d
cat >/run/systemd/system/systemd-timesyncd.service.d/10-debug.conf <<EOF
[Service]
Environment=SYSTEMD_LOG_LEVEL=debug
EOF
systemctl daemon-reload
systemctl unmask systemd-resolved
systemctl unmask systemd-timesyncd
systemctl start systemd-resolved-varlink.socket
systemctl start systemd-resolved.service
systemctl restart systemd-timesyncd
cursor="$(mktemp)"
# Should use resolved for resolving names
journalctl -n0 -q --cursor-file="$cursor"
busctl call org.freedesktop.timesync1 /org/freedesktop/timesync1 org.freedesktop.timesync1.Manager \
SetRuntimeNTPServers as 1 foo.localhost
# Only the varlink path logs this, so it tells us which resolver ran
assert_timesyncd_log "$cursor" "io.systemd.Resolve.ResolveHostname"
# Without resolved, it should fall back to getaddrinfo
systemctl stop systemd-resolved-varlink.socket systemd-resolved-monitor.socket
systemctl stop systemd-resolved.service
journalctl -n0 -q --cursor-file="$cursor"
busctl call org.freedesktop.timesync1 /org/freedesktop/timesync1 org.freedesktop.timesync1.Manager \
SetRuntimeNTPServers as 1 foo.localhost
assert_timesyncd_log "$cursor" "Failed to connect to systemd-resolved, using getaddrinfo"
}
teardown_timedated_alternate_paths() {
set +eu