3 # Test merging of a --job-mode=ignore-dependencies job into a previously
6 systemctl start
--no-block hello-after-sleep.target
8 systemctl list-jobs
> /root
/list-jobs.txt
9 while ! grep 'sleep\.service.*running' /root
/list-jobs.txt
; do
10 systemctl list-jobs
> /root
/list-jobs.txt
13 grep 'hello\.service.*waiting' /root
/list-jobs.txt ||
exit 1
15 # This is supposed to finish quickly, not wait for sleep to finish.
16 START_SEC
=$
(date -u '+%s')
17 systemctl start
--job-mode=ignore-dependencies hello
18 END_SEC
=$
(date -u '+%s')
19 ELAPSED
=$
(($END_SEC-$START_SEC))
21 [ "$ELAPSED" -lt 3 ] ||
exit 1
23 # sleep should still be running, hello not.
24 systemctl list-jobs
> /root
/list-jobs.txt
25 grep 'sleep\.service.*running' /root
/list-jobs.txt ||
exit 1
26 grep 'hello\.service' /root
/list-jobs.txt
&& exit 1
27 systemctl stop
sleep.service hello-after-sleep.target ||
exit 1
29 # Test for a crash when enqueuing a JOB_NOP when other job already exists
30 systemctl start
--no-block hello-after-sleep.target ||
exit 1
31 # hello.service should still be waiting, so these try-restarts will collapse
33 systemctl try-restart
--job-mode=fail hello.service ||
exit 1
34 systemctl try-restart hello.service ||
exit 1
35 systemctl stop hello.service
sleep.service hello-after-sleep.target ||
exit 1
37 # TODO: add more job queueing/merging tests here.
39 # Test for irreversible jobs
40 systemctl start unstoppable.service ||
exit 1
42 # This is expected to fail with 'job cancelled'
43 systemctl stop unstoppable.service
&& exit 1
44 # But this should succeed
45 systemctl stop
--job-mode=replace-irreversibly unstoppable.service ||
exit 1
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.
50 systemctl start unstoppable.service ||
exit 1
52 # Test waiting for a started unit(s) to terminate again
53 cat <<EOF > /run/systemd/system/wait2.service
55 Description=Wait for 2 seconds
57 ExecStart=/bin/sh -ec 'sleep 2'
59 cat <<EOF > /run/systemd/system/wait5fail.service
61 Description=Wait for 5 seconds and fail
63 ExecStart=/bin/sh -ec 'sleep 5; false'
67 START_SEC
=$
(date -u '+%s')
68 systemctl start
--wait wait2.service ||
exit 1
69 END_SEC
=$
(date -u '+%s')
70 ELAPSED
=$
(($END_SEC-$START_SEC))
71 [[ "$ELAPSED" -ge 2 ]] && [[ "$ELAPSED" -le 4 ]] ||
exit 1
73 # wait5fail fails, so systemctl should fail
74 START_SEC
=$
(date -u '+%s')
75 ! systemctl start
--wait wait2.service wait5fail.service ||
exit 1
76 END_SEC
=$
(date -u '+%s')
77 ELAPSED
=$
(($END_SEC-$START_SEC))
78 [[ "$ELAPSED" -ge 5 ]] && [[ "$ELAPSED" -le 7 ]] ||
exit 1