Files
podman/test/system/270-socket-activation.bats
Ed Santiago 86083c580b System tests: speed up. They've gotten too slow.
- logs: remove unnecessary sleeps. This saves ~25s.
   Unfortunately, journald seems to have some sort of lag,
   so we need to keep retrying until we get the 'after' string.

 - ps: add placeholder test for once buildah 3544 is fixed

 - cp: bulk-kill containers when finished, instead of one by one.
   This is a big change and only saves about 8s per run, but hey.

 - mount,pause,healthcheck: 'podman stop -t 0' before rm'ing containers.
   Easy 50s.
   Have I mentioned, lately, that 'podman rm -f' needs a '-t 0' flag?

 - play: same, and also 'podman pod stop'. Seems to shave ~20s.

 - socket-activation: UGH! Buggy and useless tests! They were
   running "sleep 90" containers for no reason whatsoever. I
   assume the intention was to run them with "-d", so that's
   what I've done here. Also fixed some language. 180 seconds!

(Unrelated: cleanup in 070-build, use $IMAGE, not alpine)

Signed-off-by: Ed Santiago <santiago@redhat.com>
2021-09-27 20:06:18 -06:00

105 lines
2.6 KiB
Bash

#!/usr/bin/env bats -*- bats -*-
#
# Tests podman system service under systemd socket activation
#
load helpers
load helpers.systemd
SERVICE_NAME="podman_test_$(random_string)"
SERVICE_SOCK_ADDR="/run/podman/podman.sock"
if is_rootless; then
SERVICE_SOCK_ADDR="$XDG_RUNTIME_DIR/podman/podman.sock"
fi
SERVICE_FILE="$UNIT_DIR/$SERVICE_NAME.service"
SOCKET_FILE="$UNIT_DIR/$SERVICE_NAME.socket"
function setup() {
skip_if_remote "systemd tests are meaningless over remote"
basic_setup
cat > $SERVICE_FILE <<EOF
[Unit]
Description=Podman API Service
Requires=podman.socket
After=podman.socket
Documentation=man:podman-system-service(1)
StartLimitIntervalSec=0
[Service]
Type=exec
KillMode=process
Environment=LOGGING="--log-level=info"
ExecStart=$PODMAN $LOGGING system service -t 2
EOF
cat > $SOCKET_FILE <<EOF
[Unit]
Description=Podman API Socket
Documentation=man:podman-system-service(1)
[Socket]
ListenStream=%t/podman/podman.sock
SocketMode=0660
[Install]
WantedBy=sockets.target
EOF
# ensure pause die before each test runs
if is_rootless; then
local pause_pid="$XDG_RUNTIME_DIR/libpod/tmp/pause.pid"
if [ -f $pause_pid ]; then
kill -9 $(cat $pause_pid) 2> /dev/null
rm -f $pause_pid
fi
fi
systemctl start "$SERVICE_NAME.socket"
}
function teardown() {
systemctl stop "$SERVICE_NAME.socket"
rm -f "$SERVICE_FILE" "$SOCKET_FILE"
systemctl daemon-reload
basic_teardown
}
@test "podman system service - socket activation - no container" {
run curl -s --max-time 3 --unix-socket $SERVICE_SOCK_ADDR http://podman/libpod/_ping
is "$output" "OK" "podman service responds normally"
}
@test "podman system service - socket activation - existing container" {
run_podman run -d $IMAGE sleep 90
cid="$output"
run curl -s --max-time 3 --unix-socket $SERVICE_SOCK_ADDR http://podman/libpod/_ping
is "$output" "OK" "podman service responds normally"
run_podman stop -t 0 $cid
run_podman rm -f $cid
}
@test "podman system service - socket activation - kill rootless pause" {
if ! is_rootless; then
skip "root podman no need pause process"
fi
run_podman run -d $IMAGE sleep 90
cid="$output"
local pause_pid="$XDG_RUNTIME_DIR/libpod/tmp/pause.pid"
if [ -f $pause_pid ]; then
kill -9 $(cat $pause_pid) 2> /dev/null
fi
run curl -s --max-time 3 --unix-socket $SERVICE_SOCK_ADDR http://podman/libpod/_ping
is "$output" "OK" "podman service responds normally"
run_podman stop -t 0 $cid
run_podman rm -f $cid
}
# vim: filetype=sh