]> git.ipfire.org Git - thirdparty/systemd.git/blame - test/TEST-03-JOBS/test-jobs.sh
Merge pull request #2085 from fbuihuu/more-use-of-check-load-state
[thirdparty/systemd.git] / test / TEST-03-JOBS / test-jobs.sh
CommitLineData
b5da077d
MS
1#!/bin/bash -x
2
903e7c37 3# Test merging of a --job-mode=ignore-dependencies job into a previously
b5da077d
MS
4# installed job.
5
6systemctl start --no-block hello-after-sleep.target
b46f4ef1 7
b5da077d 8systemctl list-jobs > /root/list-jobs.txt
b46f4ef1
EV
9while ! grep 'sleep\.service.*running' /root/list-jobs.txt; do
10 systemctl list-jobs > /root/list-jobs.txt
11done
12
b5da077d
MS
13grep 'hello\.service.*waiting' /root/list-jobs.txt || exit 1
14
15# This is supposed to finish quickly, not wait for sleep to finish.
16START_SEC=$(date -u '+%s')
903e7c37 17systemctl start --job-mode=ignore-dependencies hello
b5da077d
MS
18END_SEC=$(date -u '+%s')
19ELAPSED=$(($END_SEC-$START_SEC))
20
21[ "$ELAPSED" -lt 3 ] || exit 1
22
23# sleep should still be running, hello not.
24systemctl list-jobs > /root/list-jobs.txt
25grep 'sleep\.service.*running' /root/list-jobs.txt || exit 1
26grep 'hello\.service' /root/list-jobs.txt && exit 1
06c1c4f9
MS
27systemctl stop sleep.service hello-after-sleep.target || exit 1
28
59ef392e 29# Test for a crash when enqueuing a JOB_NOP when other job already exists
06c1c4f9
MS
30systemctl 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.
903e7c37 33systemctl try-restart --job-mode=fail hello.service || exit 1
06c1c4f9
MS
34systemctl try-restart hello.service || exit 1
35systemctl stop hello.service sleep.service hello-after-sleep.target || exit 1
b5da077d
MS
36
37# TODO: add more job queueing/merging tests here.
38
d710d363
MS
39# Test for irreversible jobs
40systemctl start unstoppable.service || exit 1
41
42# This is expected to fail with 'job cancelled'
43systemctl stop unstoppable.service && exit 1
44# But this should succeed
903e7c37 45systemctl stop --job-mode=replace-irreversibly unstoppable.service || exit 1
d710d363
MS
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.
50systemctl start unstoppable.service || exit 1
51
b5da077d
MS
52touch /testok
53exit 0