5 # Test merging of a --job-mode=ignore-dependencies job into a previously
8 systemctl start
--no-block hello-after-sleep.target
10 systemctl list-jobs
>/root
/list-jobs.txt
11 while ! grep 'sleep\.service.*running' /root
/list-jobs.txt
; do
12 systemctl list-jobs
>/root
/list-jobs.txt
15 grep 'hello\.service.*waiting' /root
/list-jobs.txt
17 # This is supposed to finish quickly, not wait for sleep to finish.
18 START_SEC
=$
(date -u '+%s')
19 systemctl start
--job-mode=ignore-dependencies hello
20 END_SEC
=$
(date -u '+%s')
21 ELAPSED
=$
((END_SEC-START_SEC
))
25 # sleep should still be running, hello not.
26 systemctl list-jobs
>/root
/list-jobs.txt
27 grep 'sleep\.service.*running' /root
/list-jobs.txt
28 grep 'hello\.service' /root
/list-jobs.txt
&& exit 1
29 systemctl stop
sleep.service hello-after-sleep.target
31 # Some basic testing that --show-transaction does something useful
32 systemctl is-active systemd-importd
&& { echo 'unexpected success'; exit 1; }
33 systemctl
-T start systemd-importd
34 systemctl is-active systemd-importd
35 systemctl
--show-transaction stop systemd-importd
36 systemctl is-active systemd-importd
&& { echo 'unexpected success'; exit 1; }
38 # Test for a crash when enqueuing a JOB_NOP when other job already exists
39 systemctl start
--no-block hello-after-sleep.target
40 # hello.service should still be waiting, so these try-restarts will collapse
42 systemctl try-restart
--job-mode=fail hello.service
43 systemctl try-restart hello.service
44 systemctl stop hello.service
sleep.service hello-after-sleep.target
46 # TODO: add more job queueing/merging tests here.
48 # Test for irreversible jobs
49 systemctl start unstoppable.service
51 # This is expected to fail with 'job cancelled'
52 systemctl stop unstoppable.service
&& exit 1
53 # But this should succeed
54 systemctl stop
--job-mode=replace-irreversibly unstoppable.service
56 # We're going to shutdown soon. Let's see if it succeeds when
57 # there's an active service that tries to be unstoppable.
58 # Shutdown of the container/VM will hang if not.
59 systemctl start unstoppable.service
61 # Test waiting for a started unit(s) to terminate again
62 cat <<EOF >/run/systemd/system/wait2.service
64 Description=Wait for 2 seconds
66 ExecStart=/bin/sh -ec 'sleep 2'
68 cat <<EOF >/run/systemd/system/wait5fail.service
70 Description=Wait for 5 seconds and fail
72 ExecStart=/bin/sh -ec 'sleep 5; false'
76 START_SEC
=$
(date -u '+%s')
77 systemctl start
--wait wait2.service
78 END_SEC
=$
(date -u '+%s')
79 ELAPSED
=$
((END_SEC-START_SEC
))
80 [[ "$ELAPSED" -ge 2 ]] && [[ "$ELAPSED" -le 4 ]] ||
exit 1
82 # wait5fail fails, so systemctl should fail
83 START_SEC
=$
(date -u '+%s')
84 systemctl start
--wait wait2.service wait5fail.service
&& { echo 'unexpected success'; exit 1; }
85 END_SEC
=$
(date -u '+%s')
86 ELAPSED
=$
((END_SEC-START_SEC
))
87 [[ "$ELAPSED" -ge 5 ]] && [[ "$ELAPSED" -le 7 ]] ||
exit 1
89 # Test time-limited scopes
90 START_SEC
=$
(date -u '+%s')
92 systemd-run
--scope --property=RuntimeMaxSec
=3s
sleep 10
94 END_SEC
=$
(date -u '+%s')
95 ELAPSED
=$
((END_SEC-START_SEC
))
96 [[ "$ELAPSED" -ge 3 ]] && [[ "$ELAPSED" -le 5 ]] ||
exit 1
97 [[ "$RESULT" -ne 0 ]] ||
exit 1