Skip to content

Commit 846d717

Browse files
Merge pull request #22826 from Luap99/fast-system-test-2
test/system: make some tests faster part 2
2 parents 3c244a9 + ad661b5 commit 846d717

File tree

7 files changed

+51
-79
lines changed

7 files changed

+51
-79
lines changed

test/system/030-run.bats

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,7 @@ echo $rand | 0 | $rand
127127
@test "podman run --name" {
128128
randomname=$(random_string 30)
129129

130-
# Assume that 4 seconds gives us enough time for 3 quick tests (or at
131-
# least for the 'ps'; the 'container exists' should pass even in the
132-
# unlikely case that the container exits before we get to them)
133-
run_podman run -d --name $randomname $IMAGE sleep 4
130+
run_podman run -d --name $randomname $IMAGE sleep inf
134131
cid=$output
135132

136133
run_podman ps --format '{{.Names}}--{{.ID}}'
@@ -140,7 +137,7 @@ echo $rand | 0 | $rand
140137
run_podman container exists $cid
141138

142139
# Done with live-container tests; now let's test after container finishes
143-
run_podman wait $cid
140+
run_podman stop -t0 $cid
144141

145142
# Container still exists even after stopping:
146143
run_podman container exists $randomname
@@ -1143,16 +1140,19 @@ EOF
11431140

11441141
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman 1 run --rm $IMAGE touch /testro
11451142
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm --read-only=false $IMAGE touch /testrw
1146-
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm $IMAGE touch /tmp/testrw
1147-
for dir in /tmp /var/tmp /dev /dev/shm /run; do
1148-
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm $IMAGE touch $dir/testro
1149-
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm --read-only=false $IMAGE touch $dir/testro
1150-
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm --read-only=false --read-only-tmpfs=true $IMAGE touch $dir/testro
1151-
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm --read-only-tmpfs=true $IMAGE touch $dir/testro
1152-
1153-
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman 1 run --rm --read-only-tmpfs=false $IMAGE touch $dir/testro
1154-
assert "$output" =~ "touch: $dir/testro: Read-only file system"
1155-
done
1143+
1144+
files="/tmp/a /var/tmp/b /dev/c /dev/shm/d /run/e"
1145+
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm $IMAGE touch $files
1146+
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm --read-only=false $IMAGE touch $files
1147+
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm --read-only=false --read-only-tmpfs=true $IMAGE touch $files
1148+
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm --read-only-tmpfs=true $IMAGE touch $files
1149+
1150+
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman 1 run --rm --read-only-tmpfs=false $IMAGE touch $files
1151+
assert "$output" == "touch: /tmp/a: Read-only file system
1152+
touch: /var/tmp/b: Read-only file system
1153+
touch: /dev/c: Read-only file system
1154+
touch: /dev/shm/d: Read-only file system
1155+
touch: /run/e: Read-only file system"
11561156
}
11571157

11581158
@test "podman run ulimit from containers.conf" {

test/system/035-logs.bats

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,36 +89,30 @@ function _log_test_multi() {
8989

9090
skip_if_remote "logs does not support multiple containers when run remotely"
9191

92-
# Under k8s file, 'podman logs' returns just the facts, Ma'am.
93-
# Under journald, there may be other cruft (e.g. container removals)
94-
local etc=
95-
if [[ $driver =~ journal ]]; then
96-
etc='.*'
97-
fi
98-
9992
local events_backend=$(_additional_events_backend $driver)
10093

10194
# Simple helper to make the container starts, below, easier to read
10295
local -a cid
10396
doit() {
104-
run_podman ${events_backend} run --log-driver=$driver --rm -d --name "$1" $IMAGE sh -c "$2";
97+
run_podman ${events_backend} run --log-driver=$driver -d \
98+
--name "$1" $IMAGE sh -c "$2";
10599
cid+=($(echo "${output:0:12}"))
106100
}
107101

108-
# Not really a guarantee that we'll get a-b-c-d in order, but it's
109-
# the best we can do. The trailing 'sleep' in each container
110-
# minimizes the chance of a race condition in which the container
111-
# is removed before 'podman logs' has a chance to wake up and read
112-
# the final output.
113-
doit c1 "echo a;sleep 10;echo d;sleep 3"
114-
doit c2 "sleep 1;echo b;sleep 2;echo c;sleep 3"
102+
doit c1 "echo a1; echo a2"
103+
doit c2 "echo b1; echo b2"
115104

105+
# Reading logs only guarantees the order for a single container,
106+
# when using multiple containers the line order between them can vary.
116107
run_podman ${events_backend} logs -f c1 c2
117108
assert "$output" =~ \
118-
"${cid[0]} a$etc
119-
${cid[1]} b$etc
120-
${cid[1]} c$etc
121-
${cid[0]} d" "Sequential output from logs"
109+
".*^${cid[0]} a1\$.*
110+
${cid[0]} a2" "Sequential output from c1"
111+
assert "$output" =~ \
112+
".*^${cid[1]} b1\$.*
113+
${cid[1]} b2" "Sequential output from c2"
114+
115+
run_podman rm -f -t0 ${cid[0]} ${cid[1]}
122116
}
123117

124118
@test "podman logs - multi k8s-file" {

test/system/040-ps.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ load helpers
2424
"${cid:0:12} \+$IMAGE \+sleep [0-9]\+ .*second.* $cname"\
2525
"output from podman ps"
2626

27-
# OK. Wait for sleep to finish...
28-
run_podman wait $cid
27+
# OK. Stop container now.
28+
run_podman stop -t0 $cid
2929

3030
# ...then make sure container shows up as stopped
3131
run_podman ps -a

test/system/055-rm.bats

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ function __run_healthcheck_container() {
124124
run_podman run -d --name $1 \
125125
--health-cmd /bin/false \
126126
--health-interval 1s \
127-
--health-retries 2 \
127+
--health-retries 1 \
128128
--health-timeout 1s \
129129
--health-on-failure=stop \
130-
--stop-timeout=2 \
130+
--stop-timeout=1 \
131131
--health-start-period 0 \
132132
--stop-signal SIGTERM \
133133
$IMAGE sleep infinity
@@ -156,7 +156,7 @@ function __run_healthcheck_container() {
156156
assert "$output" =~ "Error: cannot remove container $cid as it is .* - running or paused containers cannot be removed without force: container state improper" \
157157
"Expected error message from podman rm"
158158
rm_failures=$((rm_failures + 1))
159-
sleep 1
159+
sleep 0.5
160160
done
161161

162162
# At this point, container should be gone

test/system/130-kill.bats

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,18 @@ load helpers
77

88
# bats test_tags=distro-integration
99
@test "podman kill - test signal handling in containers" {
10-
11-
# Prepare for 'logs -f'
12-
run_podman info --format '{{.Host.LogDriver}}'
13-
log_driver=$output
14-
run_podman info --format '{{.Host.EventLogger}}'
15-
event_logger=$output
16-
opt_log_driver=
17-
if [ $log_driver = "journald" ] && [ $event_logger != "journald" ]; then
18-
# Since PR#10431, 'logs -f' with journald driver is only supported with journald events backend.
19-
# Set '--log driver' temporally because remote doesn't support '--events-backend'.
20-
opt_log_driver="--log-driver k8s-file"
21-
fi
10+
local cname=c-$(random_string 10)
11+
local fifo=${PODMAN_TMPDIR}/podman-kill-fifo.$(random_string 10)
12+
mkfifo $fifo
2213

2314
# Start a container that will handle all signals by emitting 'got: N'
2415
local -a signals=(1 2 3 4 5 6 8 10 12 13 14 15 16 20 21 22 23 24 25 26 64)
25-
run_podman run -d ${opt_log_driver} $IMAGE sh -c \
16+
$PODMAN run --name $cname $IMAGE sh -c \
2617
"for i in ${signals[*]}; do trap \"echo got: \$i\" \$i; done;
2718
echo READY;
2819
while ! test -e /stop; do sleep 0.1; done;
29-
echo DONE"
30-
cid="$output"
31-
32-
# Run 'logs -f' on that container, but run it in the background with
33-
# redirection to a named pipe from which we (foreground job) read
34-
# and confirm that signals are received. We can't use run_podman here.
35-
local fifo=${PODMAN_TMPDIR}/podman-kill-fifo.$(random_string 10)
36-
mkfifo $fifo
37-
$PODMAN logs -f $cid >$fifo </dev/null &
38-
podman_log_pid=$!
20+
echo DONE" &>$fifo </dev/null &
21+
podman_run_pid=$!
3922

4023
# Open the FIFO for reading, and keep it open. This prevents a race
4124
# condition in which the container can exit (e.g. if for some reason
@@ -54,7 +37,7 @@ load helpers
5437
local signal=$1
5538
local signum=${2:-$1} # e.g. if signal=HUP, we expect to see '1'
5639

57-
run_podman kill -s $signal $cid
40+
run_podman kill -s $signal $cname
5841
read -t 60 -u 5 actual || die "Timed out: no ACK for kill -s $signal"
5942
is "$actual" "got: $signum" "Signal $signal handled by container"
6043
}
@@ -74,14 +57,13 @@ load helpers
7457
# Done. Tell the container to stop, and wait for final DONE.
7558
# The '-d' is because container exit is racy: the exec process itself
7659
# could get caught and killed by cleanup, causing this step to exit 137
77-
run_podman exec -d $cid touch /stop
60+
run_podman exec -d $cname touch /stop
7861
read -t 5 -u 5 done || die "Timed out waiting for DONE from container"
7962
is "$done" "DONE" "final log message from container"
8063

8164
# Clean up
82-
run_podman wait $cid
83-
run_podman rm $cid
84-
wait $podman_log_pid
65+
run_podman rm -f -t0 $cname
66+
wait $podman_run_pid || die "wait for podman run failed"
8567
}
8668

8769
@test "podman kill - rejects invalid args" {

test/system/600-completion.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ function check_shell_completion() {
213213

214214
i=$(($i + 1))
215215
# If the argument ends with ...] than we accept 0...n args
216-
# Loop three times to make sure we are not only completing the first arg
217-
if [[ ! ${arg} =~ "..." ]] || [[ i -gt 3 ]]; then
216+
# Loop two times to make sure we are not only completing the first arg
217+
if [[ ! ${arg} =~ "..." ]] || [[ i -gt 1 ]]; then
218218
break
219219
fi
220220

test/system/700-play.bats

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ metadata:
3131
spec:
3232
containers:
3333
- command:
34-
- sleep
35-
- \"100\"
34+
- /home/podman/pause
3635
env:
3736
- name: PATH
3837
value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
@@ -811,15 +810,12 @@ EOF
811810
}
812811

813812
@test "podman kube generate tmpfs on /tmp" {
814-
KUBE=$PODMAN_TMPDIR/kube.yaml
815-
run_podman create --name test $IMAGE sleep 100
816-
run_podman kube generate test -f $KUBE
817-
run_podman kube play $KUBE
818-
run_podman exec test-pod-test sh -c "mount | grep /tmp"
813+
local yaml=$PODMAN_TMPDIR/test.yaml
814+
_write_test_yaml command=/home/podman/pause
815+
run_podman kube play $yaml
816+
run_podman exec test_pod-test sh -c "mount | grep /tmp"
819817
assert "$output" !~ "noexec" "mounts on /tmp should not be noexec"
820-
run_podman kube down $KUBE
821-
run_podman pod rm -a -f -t 0
822-
run_podman rm -a -f -t 0
818+
run_podman kube down $yaml
823819
}
824820

825821
@test "podman kube play - pull policy" {

0 commit comments

Comments
 (0)