]> git.ipfire.org Git - thirdparty/systemd.git/blame - test/TEST-03-JOBS/test-jobs.sh
test: make sure output of test TEST-03 test service ends up on console
[thirdparty/systemd.git] / test / TEST-03-JOBS / test-jobs.sh
CommitLineData
efd0b6cc 1#!/bin/bash -ex
b5da077d 2
903e7c37 3# Test merging of a --job-mode=ignore-dependencies job into a previously
b5da077d
MS
4# installed job.
5
6systemctl start --no-block hello-after-sleep.target
b46f4ef1 7
b5da077d 8systemctl list-jobs > /root/list-jobs.txt
b46f4ef1
EV
9while ! grep 'sleep\.service.*running' /root/list-jobs.txt; do
10 systemctl list-jobs > /root/list-jobs.txt
11done
12
818567fc 13grep 'hello\.service.*waiting' /root/list-jobs.txt
b5da077d
MS
14
15# This is supposed to finish quickly, not wait for sleep to finish.
16START_SEC=$(date -u '+%s')
903e7c37 17systemctl start --job-mode=ignore-dependencies hello
b5da077d
MS
18END_SEC=$(date -u '+%s')
19ELAPSED=$(($END_SEC-$START_SEC))
20
818567fc 21[ "$ELAPSED" -lt 3 ]
b5da077d
MS
22
23# sleep should still be running, hello not.
24systemctl list-jobs > /root/list-jobs.txt
818567fc 25grep 'sleep\.service.*running' /root/list-jobs.txt
b5da077d 26grep 'hello\.service' /root/list-jobs.txt && exit 1
818567fc 27systemctl stop sleep.service hello-after-sleep.target
06c1c4f9 28
59ef392e 29# Test for a crash when enqueuing a JOB_NOP when other job already exists
818567fc 30systemctl start --no-block hello-after-sleep.target
06c1c4f9
MS
31# hello.service should still be waiting, so these try-restarts will collapse
32# into NOPs.
818567fc
MP
33systemctl try-restart --job-mode=fail hello.service
34systemctl try-restart hello.service
35systemctl stop hello.service sleep.service hello-after-sleep.target
b5da077d
MS
36
37# TODO: add more job queueing/merging tests here.
38
d710d363 39# Test for irreversible jobs
818567fc 40systemctl start unstoppable.service
d710d363
MS
41
42# This is expected to fail with 'job cancelled'
43systemctl stop unstoppable.service && exit 1
44# But this should succeed
818567fc 45systemctl stop --job-mode=replace-irreversibly unstoppable.service
d710d363
MS
46
47# We're going to shutdown soon. Let's see if it succeeds when
48# there's an active service that tries to be unstoppable.
49# Shutdown of the container/VM will hang if not.
818567fc 50systemctl start unstoppable.service
d710d363 51
93a08841
MP
52# Test waiting for a started unit(s) to terminate again
53cat <<EOF > /run/systemd/system/wait2.service
54[Unit]
55Description=Wait for 2 seconds
56[Service]
57ExecStart=/bin/sh -ec 'sleep 2'
58EOF
59cat <<EOF > /run/systemd/system/wait5fail.service
60[Unit]
61Description=Wait for 5 seconds and fail
62[Service]
63ExecStart=/bin/sh -ec 'sleep 5; false'
64EOF
65
66# wait2 succeeds
67START_SEC=$(date -u '+%s')
818567fc 68systemctl start --wait wait2.service
93a08841
MP
69END_SEC=$(date -u '+%s')
70ELAPSED=$(($END_SEC-$START_SEC))
5209e9af 71[[ "$ELAPSED" -ge 2 ]] && [[ "$ELAPSED" -le 4 ]] || exit 1
93a08841
MP
72
73# wait5fail fails, so systemctl should fail
74START_SEC=$(date -u '+%s')
75! systemctl start --wait wait2.service wait5fail.service || exit 1
76END_SEC=$(date -u '+%s')
77ELAPSED=$(($END_SEC-$START_SEC))
78[[ "$ELAPSED" -ge 5 ]] && [[ "$ELAPSED" -le 7 ]] || exit 1
79
b5da077d 80touch /testok