Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a50b08f

Browse filesBrowse files
committed
TEST-07-PID1: add test cases for DeferTrigger=
1 parent 3eef949 commit a50b08f
Copy full SHA for a50b08f

File tree

Expand file treeCollapse file tree

1 file changed

+122
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+122
-0
lines changed
+122Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/usr/bin/env bash
2+
# SPDX-License-Identifier: LGPL-2.1-or-later
3+
# shellcheck disable=SC2016
4+
set -eux
5+
set -o pipefail
6+
7+
# shellcheck source=test/units/util.sh
8+
. "$(dirname "$0")"/util.sh
9+
10+
UNIT_NAME="TEST-07-PID1-socket-defer-$RANDOM"
11+
12+
at_exit() {
13+
systemctl stop "$UNIT_NAME*"
14+
rm -f /run/systemd/system/"$UNIT_NAME".socket \
15+
/run/systemd/system/"$UNIT_NAME"{,-conflict1,-conflict2,-forever}.service
16+
}
17+
18+
trap at_exit EXIT
19+
20+
mkdir -p "/tmp/$UNIT_NAME"
21+
22+
cat >/run/systemd/system/"$UNIT_NAME-conflict1.service" <<EOF
23+
[Service]
24+
Type=oneshot
25+
RemainAfterExit=yes
26+
ExecStop=bash -c 'while [[ -f /tmp/$UNIT_NAME/flag ]]; do sleep 1; done'
27+
TimeoutStopSec=infinity
28+
EOF
29+
30+
cat >/run/systemd/system/"$UNIT_NAME-conflict2.service" <<EOF
31+
[Service]
32+
ExecStart=bash -c 'while [[ -f /tmp/$UNIT_NAME/flag ]]; do sleep 1; done'
33+
EOF
34+
35+
cat >/run/systemd/system/"$UNIT_NAME-forever.service" <<EOF
36+
[Service]
37+
Type=oneshot
38+
ExecStart=sleep infinity
39+
TimeoutSec=infinity
40+
EOF
41+
42+
cat >/run/systemd/system/"$UNIT_NAME.socket" <<EOF
43+
[Socket]
44+
ListenStream=/tmp/$UNIT_NAME/test
45+
FlushPending=yes
46+
EOF
47+
48+
cat >/run/systemd/system/"$UNIT_NAME.service" <<EOF
49+
[Unit]
50+
Conflicts=$UNIT_NAME-conflict1.service
51+
Conflicts=$UNIT_NAME-conflict2.service
52+
53+
[Service]
54+
ExecStart=sleep infinity
55+
EOF
56+
57+
# DeferTrigger=no: job mode replace
58+
59+
systemctl start "$UNIT_NAME.socket"
60+
[[ -S "/tmp/$UNIT_NAME/test" ]]
61+
assert_eq "$(systemctl show "$UNIT_NAME.socket" -P SubState)" "listening"
62+
(! systemctl is-active "$UNIT_NAME.service")
63+
64+
echo 1 >"/tmp/$UNIT_NAME/test"
65+
timeout 30 bash -c "until [[ \$(systemctl show '$UNIT_NAME.socket' -P SubState) == 'running' ]]; do sleep .5; done"
66+
systemctl is-active "$UNIT_NAME.service"
67+
68+
touch "/tmp/$UNIT_NAME/flag"
69+
systemctl start "$UNIT_NAME-conflict2.service"
70+
(! systemctl is-active "$UNIT_NAME.service")
71+
assert_eq "$(systemctl show "$UNIT_NAME.socket" -P SubState)" "listening"
72+
echo 1 >"/tmp/$UNIT_NAME/test"
73+
timeout 30 bash -c "until [[ \$(systemctl show '$UNIT_NAME.socket' -P SubState) == 'running' ]]; do sleep .5; done"
74+
systemctl is-active "$UNIT_NAME.service"
75+
(! systemctl is-active "$UNIT_NAME-conflict2.service")
76+
77+
# DeferTrigger=yes
78+
79+
echo "DeferTrigger=yes" >>/run/systemd/system/"$UNIT_NAME.socket"
80+
systemctl daemon-reload
81+
82+
assert_eq "$(systemctl show "$UNIT_NAME.socket" -P SubState)" "running"
83+
systemctl start "$UNIT_NAME-conflict1.service"
84+
(! systemctl is-active "$UNIT_NAME.service")
85+
assert_eq "$(systemctl show "$UNIT_NAME.socket" -P SubState)" "listening"
86+
87+
# Wait for running stop job in "deferred" state
88+
89+
systemctl stop --no-block "$UNIT_NAME-conflict1.service"
90+
assert_eq "$(systemctl show "$UNIT_NAME.socket" -P SubState)" "stop"
91+
echo 1 >"/tmp/$UNIT_NAME/test"
92+
timeout 30 bash -c "until [[ \$(systemctl show '$UNIT_NAME.socket' -P SubState) == 'deferred' ]]; do sleep .5; done"
93+
(! systemctl is-active "$UNIT_NAME.service")
94+
95+
# Return to "listening" on daemon-reload
96+
97+
systemctl daemon-reload
98+
assert_eq "$(systemctl show "$UNIT_NAME.socket" -P SubState)" "listening"
99+
echo 1 >"/tmp/$UNIT_NAME/test"
100+
timeout 30 bash -c "until [[ \$(systemctl show '$UNIT_NAME.socket' -P SubState) == 'deferred' ]]; do sleep .5; done"
101+
(! systemctl is-active "$UNIT_NAME.service")
102+
103+
# Activate after conflicting unit exits
104+
105+
rm "/tmp/$UNIT_NAME/flag"
106+
timeout 30 bash -c "while systemctl -q is-active '$UNIT_NAME-conflict1.service'; do sleep .2; done"
107+
timeout 30 bash -c "until [[ \$(systemctl show '$UNIT_NAME.socket' -P SubState) == 'running' ]]; do sleep .5; done"
108+
systemctl is-active "$UNIT_NAME.service"
109+
110+
# An irrelevant job running, during which one of the conflicting units exits
111+
112+
touch "/tmp/$UNIT_NAME/flag"
113+
systemctl start "$UNIT_NAME-forever.service" "$UNIT_NAME-conflict2.service"
114+
assert_eq "$(systemctl show "$UNIT_NAME.socket" -P SubState)" "listening"
115+
echo 1 >"/tmp/$UNIT_NAME/test"
116+
timeout 30 bash -c "until [[ \$(systemctl show '$UNIT_NAME.socket' -P SubState) == 'deferred' ]]; do sleep .5; done"
117+
(! systemctl is-active "$UNIT_NAME.service")
118+
rm "/tmp/$UNIT_NAME/flag"
119+
timeout 30 bash -c "while systemctl -q is-active '$UNIT_NAME-conflict2.service'; do sleep .2; done"
120+
timeout 30 bash -c "until [[ \$(systemctl show '$UNIT_NAME.socket' -P SubState) == 'running' ]]; do sleep .5; done"
121+
systemctl is-active "$UNIT_NAME.service"
122+
assert_eq "$(systemctl show "$UNIT_NAME-forever.service" -P SubState)" "start"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.