chiark / gitweb /
test: add test for crash when adding a JOB_NOP
[elogind.git] / test / TEST-03-JOBS / test-jobs.sh
1 #!/bin/bash -x
2
3 # Test merging of a --ignore-dependencies job into a previously
4 # installed job.
5
6 systemctl start --no-block hello-after-sleep.target
7 # sleep is now running, hello/start is waiting. Verify that:
8 systemctl list-jobs > /root/list-jobs.txt
9 grep 'sleep\.service.*running' /root/list-jobs.txt || exit 1
10 grep 'hello\.service.*waiting' /root/list-jobs.txt || exit 1
11
12 # This is supposed to finish quickly, not wait for sleep to finish.
13 START_SEC=$(date -u '+%s')
14 systemctl start --ignore-dependencies hello
15 END_SEC=$(date -u '+%s')
16 ELAPSED=$(($END_SEC-$START_SEC))
17
18 [ "$ELAPSED" -lt 3 ] || exit 1
19
20 # sleep should still be running, hello not.
21 systemctl list-jobs > /root/list-jobs.txt
22 grep 'sleep\.service.*running' /root/list-jobs.txt || exit 1
23 grep 'hello\.service' /root/list-jobs.txt && exit 1
24 systemctl stop sleep.service hello-after-sleep.target || exit 1
25
26 # Test for a crash when enqueueing a JOB_NOP when other job already exists
27 systemctl start --no-block hello-after-sleep.target || exit 1
28 # hello.service should still be waiting, so these try-restarts will collapse
29 # into NOPs.
30 systemctl try-restart --fail hello.service || exit 1
31 systemctl try-restart hello.service || exit 1
32 systemctl stop hello.service sleep.service hello-after-sleep.target || exit 1
33
34 # TODO: add more job queueing/merging tests here.
35
36 # Test for irreversible jobs
37 systemctl start unstoppable.service || exit 1
38
39 # This is expected to fail with 'job cancelled'
40 systemctl stop unstoppable.service && exit 1
41 # But this should succeed
42 systemctl stop --irreversible unstoppable.service || exit 1
43
44 # We're going to shutdown soon. Let's see if it succeeds when
45 # there's an active service that tries to be unstoppable.
46 # Shutdown of the container/VM will hang if not.
47 systemctl start unstoppable.service || exit 1
48
49 touch /testok
50 exit 0