mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 17:51:22 +03:00
5209e9afd2
If the "systemctl start" happens at an "unlucky" time such as 1000.9 seconds and then e. g. runs for 2.6 s (sleep 2 plus the overhead of starting the unit and waiting for it) the END_SEC would be 1003.5s which would round to 1004, making the difference 4. On busier testbeds the overhead apparently can take a bit more than 0.5s. The main point is really that it doesn't wait that much longer, so "-le 4" seems perfectly fine. We allow up to 1.5s in the subsequent "wait5fail" test below too. Fixes #4582
81 lines
2.6 KiB
Bash
Executable File
81 lines
2.6 KiB
Bash
Executable File
#!/bin/bash -x
|
|
|
|
# Test merging of a --job-mode=ignore-dependencies job into a previously
|
|
# installed job.
|
|
|
|
systemctl start --no-block hello-after-sleep.target
|
|
|
|
systemctl list-jobs > /root/list-jobs.txt
|
|
while ! grep 'sleep\.service.*running' /root/list-jobs.txt; do
|
|
systemctl list-jobs > /root/list-jobs.txt
|
|
done
|
|
|
|
grep 'hello\.service.*waiting' /root/list-jobs.txt || exit 1
|
|
|
|
# This is supposed to finish quickly, not wait for sleep to finish.
|
|
START_SEC=$(date -u '+%s')
|
|
systemctl start --job-mode=ignore-dependencies hello
|
|
END_SEC=$(date -u '+%s')
|
|
ELAPSED=$(($END_SEC-$START_SEC))
|
|
|
|
[ "$ELAPSED" -lt 3 ] || exit 1
|
|
|
|
# sleep should still be running, hello not.
|
|
systemctl list-jobs > /root/list-jobs.txt
|
|
grep 'sleep\.service.*running' /root/list-jobs.txt || exit 1
|
|
grep 'hello\.service' /root/list-jobs.txt && exit 1
|
|
systemctl stop sleep.service hello-after-sleep.target || exit 1
|
|
|
|
# Test for a crash when enqueuing a JOB_NOP when other job already exists
|
|
systemctl start --no-block hello-after-sleep.target || exit 1
|
|
# hello.service should still be waiting, so these try-restarts will collapse
|
|
# into NOPs.
|
|
systemctl try-restart --job-mode=fail hello.service || exit 1
|
|
systemctl try-restart hello.service || exit 1
|
|
systemctl stop hello.service sleep.service hello-after-sleep.target || exit 1
|
|
|
|
# TODO: add more job queueing/merging tests here.
|
|
|
|
# Test for irreversible jobs
|
|
systemctl start unstoppable.service || exit 1
|
|
|
|
# This is expected to fail with 'job cancelled'
|
|
systemctl stop unstoppable.service && exit 1
|
|
# But this should succeed
|
|
systemctl stop --job-mode=replace-irreversibly unstoppable.service || exit 1
|
|
|
|
# We're going to shutdown soon. Let's see if it succeeds when
|
|
# there's an active service that tries to be unstoppable.
|
|
# Shutdown of the container/VM will hang if not.
|
|
systemctl start unstoppable.service || exit 1
|
|
|
|
# Test waiting for a started unit(s) to terminate again
|
|
cat <<EOF > /run/systemd/system/wait2.service
|
|
[Unit]
|
|
Description=Wait for 2 seconds
|
|
[Service]
|
|
ExecStart=/bin/sh -ec 'sleep 2'
|
|
EOF
|
|
cat <<EOF > /run/systemd/system/wait5fail.service
|
|
[Unit]
|
|
Description=Wait for 5 seconds and fail
|
|
[Service]
|
|
ExecStart=/bin/sh -ec 'sleep 5; false'
|
|
EOF
|
|
|
|
# wait2 succeeds
|
|
START_SEC=$(date -u '+%s')
|
|
systemctl start --wait wait2.service || exit 1
|
|
END_SEC=$(date -u '+%s')
|
|
ELAPSED=$(($END_SEC-$START_SEC))
|
|
[[ "$ELAPSED" -ge 2 ]] && [[ "$ELAPSED" -le 4 ]] || exit 1
|
|
|
|
# wait5fail fails, so systemctl should fail
|
|
START_SEC=$(date -u '+%s')
|
|
! systemctl start --wait wait2.service wait5fail.service || exit 1
|
|
END_SEC=$(date -u '+%s')
|
|
ELAPSED=$(($END_SEC-$START_SEC))
|
|
[[ "$ELAPSED" -ge 5 ]] && [[ "$ELAPSED" -le 7 ]] || exit 1
|
|
|
|
touch /testok
|