Merge pull request #22821 from Luap99/fast-system-test

test/system: make some tests faster part 1
This commit is contained in:
openshift-merge-bot[bot]
2024-05-28 14:44:40 +00:00
committed by GitHub
7 changed files with 77 additions and 76 deletions

View File

@ -778,7 +778,7 @@ json-file | f
@test "podman run --timeout - basic test" {
cid=timeouttest
t0=$SECONDS
run_podman 255 run --name $cid --timeout 10 $IMAGE sleep 60
run_podman 255 run --name $cid --timeout 2 $IMAGE sleep 60
t1=$SECONDS
# Confirm that container is stopped. Podman-remote unfortunately
# cannot tell the difference between "stopped" and "exited", and
@ -790,8 +790,8 @@ json-file | f
# This operation should take
# exactly 10 seconds. Give it some leeway.
delta_t=$(( $t1 - $t0 ))
assert "$delta_t" -gt 8 "podman stop: ran too quickly!"
assert "$delta_t" -le 14 "podman stop: took too long"
assert "$delta_t" -gt 1 "podman stop: ran too quickly!"
assert "$delta_t" -le 6 "podman stop: took too long"
run_podman rm $cid
}

View File

@ -136,20 +136,6 @@ load helpers
run_podman rm -t 0 -f $cid
}
@test "podman exec --wait" {
skip_if_remote "test is meaningless over remote"
# wait on bogus container
run_podman 125 exec --wait 5 "bogus_container" echo hello
assert "$output" = "Error: timed out waiting for container: bogus_container"
run_podman create --name "wait_container" $IMAGE top
run_podman 255 exec --wait 5 "wait_container" echo hello
assert "$output" = "Error: can only create exec sessions on running containers: container state improper"
run_podman rm -f wait_container
}
@test "podman run umask" {
umask="0724"
run_podman run --rm -q $IMAGE grep Umask /proc/self/status

View File

@ -7,41 +7,34 @@ load helpers
load helpers.network
# bats test_tags=distro-integration
@test "events with a filter by label" {
@test "events with a filter by label and --no-trunc option" {
cname=test-$(random_string 30 | tr A-Z a-z)
labelname=$(random_string 10)
labelvalue=$(random_string 15)
run_podman run --label $labelname=$labelvalue --name $cname --rm $IMAGE ls
before=$(date --iso-8601=seconds)
run_podman run -d --label $labelname=$labelvalue --name $cname --rm $IMAGE true
id="$output"
expect=".* container start [0-9a-f]\+ (image=$IMAGE, name=$cname,.* ${labelname}=${labelvalue}"
run_podman events --filter type=container -f container=$cname --filter label=${labelname}=${labelvalue} --filter event=start --stream=false
expect=".* container start $id (image=$IMAGE, name=$cname,.* ${labelname}=${labelvalue}"
run_podman events --since "$before" --filter type=container -f container=$cname --filter label=${labelname}=${labelvalue} --filter event=start --stream=false
is "$output" "$expect" "filtering by container name and label"
# Same thing, but without the container-name filter
run_podman system events -f type=container --filter label=${labelname}=${labelvalue} --filter event=start --stream=false
run_podman system events --since "$before" -f type=container --filter label=${labelname}=${labelvalue} --filter event=start --stream=false
is "$output" "$expect" "filtering just by label"
# Now filter just by container name, no label
run_podman events --filter type=container --filter container=$cname --filter event=start --stream=false
run_podman events --since "$before" --filter type=container --filter container=$cname --filter event=start --stream=false
is "$output" "$expect" "filtering just by container"
}
@test "truncate events" {
cname=test-$(random_string 30 | tr A-Z a-z)
run_podman run -d --name=$cname --rm $IMAGE echo hi
id="$output"
run_podman events --filter container=$cname --filter event=start --stream=false
is "$output" ".* $id " "filtering by container name full id"
# check --no-trunc=false
truncID=${id:0:12}
run_podman events --filter container=$cname --filter event=start --stream=false --no-trunc=false
run_podman events --since "$before" --filter container=$cname --filter event=start --stream=false --no-trunc=false
is "$output" ".* $truncID " "filtering by container name trunc id"
# --no-trunc does not affect --format; we always get the full ID
run_podman events --filter container=$cname --filter event=died --stream=false --format='{{.ID}}--{{.Image}}' --no-trunc=false
run_podman events --since "$before" --filter container=$cname --filter event=died --stream=false --format='{{.ID}}--{{.Image}}' --no-trunc=false
assert "$output" = "${id}--${IMAGE}"
}

View File

@ -142,14 +142,16 @@ function service_cleanup() {
@test "podman generate systemd - envar" {
cname=$(random_string)
FOO=value BAR=%s run_podman create --name $cname --env FOO -e BAR --env MYVAR=myval \
$IMAGE sh -c 'printenv && sleep 100'
$IMAGE sh -c 'printenv && echo READY; trap 'exit' SIGTERM; while :; do sleep 0.1; done'
# Start systemd service to run this container
service_setup
# Give container time to start; make sure output looks top-like
sleep 2
run_podman logs $cname
# Give container time to start and print output
# wait_for_ready returns directly if the logs matches and preserves $output
# for us so we do not have to call podman logs again here if we match the env below.
wait_for_ready $cname
is "$output" ".*FOO=value.*" "FOO environment variable set"
is "$output" ".*BAR=%s.*" "BAR environment variable set"
is "$output" ".*MYVAR=myval.*" "MYVAL environment variable set"
@ -397,13 +399,13 @@ spec:
- command:
- sh
- -c
- echo a stdout; echo a stderr 1>&2; sleep inf
- echo a stdout; echo a stderr 1>&2; trap 'exit' SIGTERM; while :; do sleep 0.1; done
image: $IMAGE
name: a
- command:
- sh
- -c
- echo b stdout; echo b stderr 1>&2; sleep inf
- echo b stdout; echo b stderr 1>&2; trap 'exit' SIGTERM; while :; do sleep 0.1; done
image: $IMAGE
name: b
EOF

View File

@ -132,7 +132,6 @@ function _confirm_update() {
# Image has already been pulled, so this shouldn't take too long
local timeout=10
while [[ $timeout -gt 0 ]]; do
sleep 1
run_podman '?' inspect --format "{{.Image}}" $cname
if [[ $status != 0 ]]; then
if [[ $output =~ (no such object|does not exist in database): ]]; then
@ -144,6 +143,7 @@ function _confirm_update() {
elif [[ $output != $old_iid ]]; then
return
fi
sleep 1
timeout=$((timeout - 1))
done
@ -417,7 +417,7 @@ EOF
Description=Podman auto-update testing timer
[Timer]
OnCalendar=*-*-* *:*:0/2
OnActiveSec=0s
Persistent=true
[Install]

View File

@ -475,31 +475,41 @@ none | true | false | 0
none | false | false | 0
"
# I am sorry, this is a long test as we need to test the upper matrix
# twice. The first run is using the default sdnotify policy of "ignore".
# In each iteration we switch between the sdnotify policy ignore and conmon.
# We could run them in a loop for each case but the test is slow so let's
# just switch between them as it should cover both policies sufficiently.
# Note because of this make sure to have at least two exit code cases directly
# after each other above so both polices will get at least once the error case.
# The first run is using the default sdnotify policy of "ignore".
# In this case, the service container serves as the main PID of the service
# to have a minimal resource footprint. The second run is using the
# "conmon" sdnotify policy in which case Podman needs to serve as the main
# PID to act as an sdnotify proxy; there Podman will wait for the service
# container to exit and reflects its exit code.
sdnotify_policy=ignore
while read exit_code_prop cmd1 cmd2 exit_code; do
for sdnotify_policy in ignore conmon; do
generate_exit_code_yaml $fname $cmd1 $cmd2 $sdnotify_policy
yaml_sha=$(sha256sum $fname)
service_container="${yaml_sha:0:12}-service"
podman_exit=$exit_code
if [[ $sdnotify_policy == "ignore" ]];then
podman_exit=0
fi
run_podman $podman_exit kube play --service-exit-code-propagation="$exit_code_prop" --service-container $fname
# Make sure that there are no error logs (e.g., #19715)
assert "$output" !~ "error msg="
run_podman container inspect --format '{{.KubeExitCodePropagation}}' $service_container
is "$output" "$exit_code_prop" "service container has the expected policy set in its annotations"
run_podman wait $service_container
is "$output" "$exit_code" "service container exit code (propagation: $exit_code_prop, policy: $service_policy, cmds: $cmd1 + $cmd2)"
run_podman kube down $fname
done
generate_exit_code_yaml $fname $cmd1 $cmd2 $sdnotify_policy
yaml_sha=$(sha256sum $fname)
service_container="${yaml_sha:0:12}-service"
podman_exit=$exit_code
if [[ $sdnotify_policy == "ignore" ]];then
podman_exit=0
fi
run_podman $podman_exit kube play --service-exit-code-propagation="$exit_code_prop" --service-container $fname
# Make sure that there are no error logs (e.g., #19715)
assert "$output" !~ "error msg="
run_podman container inspect --format '{{.KubeExitCodePropagation}}' $service_container
is "$output" "$exit_code_prop" "service container has the expected policy set in its annotations"
run_podman wait $service_container
is "$output" "$exit_code" "service container exit code (propagation: $exit_code_prop, policy: $sdnotify_policy, cmds: $cmd1 + $cmd2)"
run_podman kube down $fname
# in each iteration switch between conmon/ignore policy to get coverage for both
if [[ $sdnotify_policy == "ignore" ]]; then
sdnotify_policy=conmon
else
sdnotify_policy=ignore
fi
done < <(parse_table "$exit_tests")
# A final smoke test to make sure bogus policies lead to an error

View File

@ -633,21 +633,33 @@ EOF
# kube play --wait=true, where we clear up the created containers, pods, and volumes when a kill or sigterm is triggered
@test "podman kube play --wait with siginterrupt" {
cname=c$(random_string 15)
fname="/tmp/play_kube_wait_$(random_string 6).yaml"
run_podman container create --name $cname $IMAGE top
run_podman kube generate -f $fname $cname
# delete the container we generated from
run_podman rm -f $cname
fname="$PODMAN_TMPDIR/play_kube_wait_$(random_string 6).yaml"
echo "
apiVersion: v1
kind: Pod
metadata:
labels:
app: test
name: test_pod
spec:
restartPolicy: Never
containers:
- name: server
image: $IMAGE
command:
- top
" > $fname
# force a timeout to happen so that the kube play command is killed
# and expect the timeout code 124 to happen so that we can clean up
local t0=$SECONDS
PODMAN_TIMEOUT=15 run_podman 124 kube play --wait $fname
PODMAN_TIMEOUT=2 run_podman 124 kube play --wait $fname
local t1=$SECONDS
local delta_t=$((t1 - t0))
assert $delta_t -le 20 \
"podman kube play did not get killed within 10 seconds"
assert $delta_t -le 3 \
"podman kube play did not get killed within 3 seconds"
# Make sure we actually got SIGTERM and podman printed its message.
assert "$output" =~ "Cleaning up containers, pods, and volumes" "kube play printed sigterm message"
# there should be no containers running or created
run_podman ps -aq
@ -656,7 +668,7 @@ EOF
}
@test "podman kube play --wait - wait for pod to exit" {
fname="/tmp/play_kube_wait_$(random_string 6).yaml"
fname="$PODMAN_TMPDIR/play_kube_wait_$(random_string 6).yaml"
echo "
apiVersion: v1
kind: Pod
@ -881,8 +893,7 @@ spec:
done
assert $output == "2-healthy" "After 3 seconds"
run_podman kube down $fname
run_podman pod rm -a
run_podman pod rm -fa -t0
run_podman rm -a
}
@ -934,8 +945,7 @@ spec:
done
assert $output == "2-unhealthy" "After 3 seconds"
run_podman kube down $fname
run_podman pod rm -a
run_podman pod rm -fa -t0
run_podman rm -a
}