]>
Commit | Line | Data |
---|---|---|
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 | ||
6 | systemctl start --no-block hello-after-sleep.target | |
b46f4ef1 | 7 | |
b5da077d | 8 | systemctl list-jobs > /root/list-jobs.txt |
b46f4ef1 EV |
9 | while ! grep 'sleep\.service.*running' /root/list-jobs.txt; do |
10 | systemctl list-jobs > /root/list-jobs.txt | |
11 | done | |
12 | ||
818567fc | 13 | grep 'hello\.service.*waiting' /root/list-jobs.txt |
b5da077d MS |
14 | |
15 | # This is supposed to finish quickly, not wait for sleep to finish. | |
16 | START_SEC=$(date -u '+%s') | |
903e7c37 | 17 | systemctl start --job-mode=ignore-dependencies hello |
b5da077d MS |
18 | END_SEC=$(date -u '+%s') |
19 | ELAPSED=$(($END_SEC-$START_SEC)) | |
20 | ||
818567fc | 21 | [ "$ELAPSED" -lt 3 ] |
b5da077d MS |
22 | |
23 | # sleep should still be running, hello not. | |
24 | systemctl list-jobs > /root/list-jobs.txt | |
818567fc | 25 | grep 'sleep\.service.*running' /root/list-jobs.txt |
b5da077d | 26 | grep 'hello\.service' /root/list-jobs.txt && exit 1 |
818567fc | 27 | systemctl stop sleep.service hello-after-sleep.target |
06c1c4f9 | 28 | |
f087c7e0 LP |
29 | # Some basic testing that --show-transaction does something useful |
30 | ! systemctl is-active systemd-importd | |
31 | systemctl -T start systemd-importd | |
32 | systemctl is-active systemd-importd | |
33 | systemctl --show-transaction stop systemd-importd | |
34 | ! systemctl is-active systemd-importd | |
35 | ||
59ef392e | 36 | # Test for a crash when enqueuing a JOB_NOP when other job already exists |
818567fc | 37 | systemctl start --no-block hello-after-sleep.target |
06c1c4f9 MS |
38 | # hello.service should still be waiting, so these try-restarts will collapse |
39 | # into NOPs. | |
818567fc MP |
40 | systemctl try-restart --job-mode=fail hello.service |
41 | systemctl try-restart hello.service | |
42 | systemctl stop hello.service sleep.service hello-after-sleep.target | |
b5da077d MS |
43 | |
44 | # TODO: add more job queueing/merging tests here. | |
45 | ||
d710d363 | 46 | # Test for irreversible jobs |
818567fc | 47 | systemctl start unstoppable.service |
d710d363 MS |
48 | |
49 | # This is expected to fail with 'job cancelled' | |
50 | systemctl stop unstoppable.service && exit 1 | |
51 | # But this should succeed | |
818567fc | 52 | systemctl stop --job-mode=replace-irreversibly unstoppable.service |
d710d363 MS |
53 | |
54 | # We're going to shutdown soon. Let's see if it succeeds when | |
55 | # there's an active service that tries to be unstoppable. | |
56 | # Shutdown of the container/VM will hang if not. | |
818567fc | 57 | systemctl start unstoppable.service |
d710d363 | 58 | |
93a08841 MP |
59 | # Test waiting for a started unit(s) to terminate again |
60 | cat <<EOF > /run/systemd/system/wait2.service | |
61 | [Unit] | |
62 | Description=Wait for 2 seconds | |
63 | [Service] | |
64 | ExecStart=/bin/sh -ec 'sleep 2' | |
65 | EOF | |
66 | cat <<EOF > /run/systemd/system/wait5fail.service | |
67 | [Unit] | |
68 | Description=Wait for 5 seconds and fail | |
69 | [Service] | |
70 | ExecStart=/bin/sh -ec 'sleep 5; false' | |
71 | EOF | |
72 | ||
73 | # wait2 succeeds | |
74 | START_SEC=$(date -u '+%s') | |
818567fc | 75 | systemctl start --wait wait2.service |
93a08841 MP |
76 | END_SEC=$(date -u '+%s') |
77 | ELAPSED=$(($END_SEC-$START_SEC)) | |
5209e9af | 78 | [[ "$ELAPSED" -ge 2 ]] && [[ "$ELAPSED" -le 4 ]] || exit 1 |
93a08841 MP |
79 | |
80 | # wait5fail fails, so systemctl should fail | |
81 | START_SEC=$(date -u '+%s') | |
82 | ! systemctl start --wait wait2.service wait5fail.service || exit 1 | |
83 | END_SEC=$(date -u '+%s') | |
84 | ELAPSED=$(($END_SEC-$START_SEC)) | |
85 | [[ "$ELAPSED" -ge 5 ]] && [[ "$ELAPSED" -le 7 ]] || exit 1 | |
86 | ||
9ed7de60 PW |
87 | # Test time-limited scopes |
88 | START_SEC=$(date -u '+%s') | |
89 | set +e | |
90 | systemd-run --scope --property=RuntimeMaxSec=3s sleep 10 | |
91 | RESULT=$? | |
92 | END_SEC=$(date -u '+%s') | |
93 | ELAPSED=$(($END_SEC-$START_SEC)) | |
94 | [[ "$ELAPSED" -ge 3 ]] && [[ "$ELAPSED" -le 5 ]] || exit 1 | |
95 | [[ "$RESULT" -ne 0 ]] || exit 1 | |
96 | ||
b5da077d | 97 | touch /testok |