]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/TEST-03-JOBS/test-jobs.sh
Merge pull request #2350 from evverx/fix-memory-leak-on-failed-preset-all
[thirdparty/systemd.git] / test / TEST-03-JOBS / test-jobs.sh
1 #!/bin/bash -x
2
3 # Test merging of a --job-mode=ignore-dependencies job into a previously
4 # installed job.
5
6 systemctl start --no-block hello-after-sleep.target
7
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
11 done
12
13 grep 'hello\.service.*waiting' /root/list-jobs.txt || exit 1
14
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))
20
21 [ "$ELAPSED" -lt 3 ] || exit 1
22
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
28
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
32 # into NOPs.
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
36
37 # TODO: add more job queueing/merging tests here.
38
39 # Test for irreversible jobs
40 systemctl start unstoppable.service || exit 1
41
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
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.
50 systemctl start unstoppable.service || exit 1
51
52 touch /testok
53 exit 0