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