summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJakub Guzik <jguzik@redhat.com>2022-07-06 20:26:31 +0200
committerJakub Guzik <jguzik@redhat.com>2022-07-06 20:26:31 +0200
commit44bd166b3d9d39d8f1bcd987023c7b8de797e81a (patch)
tree5120eec98f56d5d7a8dfdb252c204a4faa40f828 /test
parent72aa00aca00467ee17cd971e2234379c1f694551 (diff)
downloadpodman-44bd166b3d9d39d8f1bcd987023c7b8de797e81a.tar.gz
podman-44bd166b3d9d39d8f1bcd987023c7b8de797e81a.tar.bz2
podman-44bd166b3d9d39d8f1bcd987023c7b8de797e81a.zip
test-apiv2: streamed response testing based on response duration
Signed-off-by: Jakub Guzik <jguzik@redhat.com>
Diffstat (limited to 'test')
-rw-r--r--test/apiv2/40-pods.at2
-rwxr-xr-xtest/apiv2/test-apiv226
2 files changed, 27 insertions, 1 deletions
diff --git a/test/apiv2/40-pods.at b/test/apiv2/40-pods.at
index 0a5201213..80724a8d9 100644
--- a/test/apiv2/40-pods.at
+++ b/test/apiv2/40-pods.at
@@ -134,4 +134,6 @@ t GET libpod/pods/json?filters='{"label":["testl' 400 \
t DELETE libpod/pods/foo 200
t DELETE "libpod/pods/foo (pod has already been deleted)" 404
+t_timeout 5 GET "libpod/pods/stats?stream=true&delay=1" 200
+
# vim: filetype=sh
diff --git a/test/apiv2/test-apiv2 b/test/apiv2/test-apiv2
index 8548d84e5..0fd282854 100755
--- a/test/apiv2/test-apiv2
+++ b/test/apiv2/test-apiv2
@@ -56,6 +56,9 @@ fi
# Path to podman binary
PODMAN_BIN=${PODMAN:-${CONTAINERS_HELPER_BINARY_DIR}/podman}
+# Timeout for streamed responses
+CURL_TIMEOUT=0
+
# Cleanup handlers
clean_up_server() {
if [ -n "$service_pid" ]; then
@@ -217,6 +220,21 @@ function jsonify() {
}
#######
+# t_timeout # Timeout wrapper for test helper
+#######
+function t_timeout() {
+ CURL_TIMEOUT=$1; shift
+ local min_runtime=$((CURL_TIMEOUT - 1))
+ start=`date +%s`
+ t $@
+ local end=`date +%s`
+ local runtime=$((end-start))
+ if ! [[ "$runtime" -ge "$min_runtime" ]]; then
+ die "Error: Streaming time should be greater or equal to '$min_runtime'"
+ fi
+}
+
+#######
# t # Main test helper
#######
function t() {
@@ -226,6 +244,12 @@ function t() {
local content_type="application/json"
local testname="$method $path"
+
+ if [[ $CURL_TIMEOUT != 0 ]]; then
+ local c_timeout=$CURL_TIMEOUT
+ curl_args+=("-m $CURL_TIMEOUT")
+ CURL_TIMEOUT=0 # 'consume' timeout
+ fi
# POST and PUT requests may be followed by one or more key=value pairs.
# Slurp the command line until we see a 3-digit status code.
if [[ $method = "POST" || $method == "PUT" ]]; then
@@ -291,7 +315,7 @@ function t() {
-o $WORKDIR/curl.result.out "$url"); rc=$?; } || :
# Any error from curl is instant bad news, from which we can't recover
- if [[ $rc -ne 0 ]]; then
+ if [[ $rc -ne 0 ]] && [[ $c_timeout -eq 0 ]]; then
die "curl failure ($rc) on $url - cannot continue"
fi