Browse Source

Adjust nextcloud-fpm and wordpress-fpm tests to use cgi-fcgi instead of nginx

add retry to php-fpm test to fix "racy" test
Joe Ferguson 6 years ago
parent
commit
fcae6a04f9

+ 0 - 36
test/tests/nextcloud-fpm-run/nginx-default.conf

@@ -1,36 +0,0 @@
-# Minimal server config
-
-server {
-	listen 80;
-	root /var/www/html;
-
-	location = /.well-known/carddav {
-		return 301 $scheme://$host/remote.php/dav;
-	}
-	location = /.well-known/caldav {
-		return 301 $scheme://$host/remote.php/dav;
-	}
-
-	location / {
-		rewrite ^ /index.php$request_uri;
-	}
-
-	location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
-		deny all;
-	}
-	location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
-		deny all;
-	}
-
-	location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\.php(?:$|/) {
-		fastcgi_split_path_info ^(.+\.php)(/.*)$;
-		include fastcgi_params;
-		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
-		fastcgi_pass fpm:9000;
-	}
-
-	location ~ ^/(?:updater|ocs-provider)(?:$|/) {
-		try_files $uri/ =404;
-		index index.php;
-	}
-}

+ 26 - 25
test/tests/nextcloud-fpm-run/run.sh

@@ -3,44 +3,45 @@ set -eo pipefail
 
 dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
 
-# since we have curl in the php image, we'll use that
-clientImage="$1"
-serverImage="$1"
-
-# Create an instance of the container-under-test
-cid="$(docker run -d "$serverImage")"
-trap "docker rm -vf $cid > /dev/null" EXIT
+image="$1"
 
 # Build a client image with cgi-fcgi for testing
-nginxImage="$("$dir/../image-name.sh" librarytest/nextcloud-fpm-run-nginx "$1")"
-"$dir/../docker-build.sh" "$dir" "$nginxImage" <<EOD
-FROM nginx:alpine
-COPY dir/nginx-default.conf /etc/nginx/conf.d/default.conf
-EOD
+clientImage='librarytest/nextcloud-fpm-run:fcgi-client'
+docker build -t "$clientImage" - > /dev/null <<'EOF'
+FROM debian:stretch-slim
 
-serverImage="$1"
+RUN set -x && apt-get update && apt-get install -y libfcgi0ldbl && rm -rf /var/lib/apt/lists/*
+
+ENTRYPOINT ["cgi-fcgi"]
+EOF
 
 # Create an instance of the container-under-test
-cid="$(docker run -d "$serverImage")"
+cid="$(docker run -d "$image")"
 trap "docker rm -vf $cid > /dev/null" EXIT
-nginxCid="$(docker run -d --link "$cid":fpm --volumes-from "$cid" "$nginxImage")"
-trap "docker rm -vf $nginxCid $cid > /dev/null" EXIT
 
-_request() {
+fcgi-request() {
 	local method="$1"
-	shift
-
-	local url="${1#/}"
-	shift
 
-	docker run --rm --link "$nginxCid":nginx "$clientImage" \
-		curl -fsL -X"$method" "$@" "http://nginx/$url"
+	local url="$2"
+	local queryString=
+	if [[ "$url" == *\?* ]]; then
+		queryString="${url#*\?}"
+		url="${url%%\?*}"
+	fi
+
+	docker run --rm -i --link "$cid":fpm \
+		-e REQUEST_METHOD="$method" \
+		-e SCRIPT_NAME="$url" \
+		-e SCRIPT_FILENAME=/var/www/html/"${url#/}" \
+		-e QUERY_STRING="$queryString" \
+		"$clientImage" \
+		-bind -connect fpm:9000
 }
 
 # Make sure that PHP-FPM is listening and ready
-. "$dir/../../retry.sh" --tries 30 '_request GET / --output /dev/null'
+. "$dir/../../retry.sh" --tries 30 'fcgi-request GET /index.php' > /dev/null 2>&1
 
 # Check that we can request / and that it contains the pattern "Finish setup" somewhere
 # <input type="submit" class="primary" value="Finish setup" data-finishing="Finishing …">
-_request GET '/' |tac|tac| grep -iq "Finish setup"
+fcgi-request GET '/index.php' |tac|tac| grep -iq "Finish setup"
 # (without "|tac|tac|" we get "broken pipe" since "grep" closes the pipe before "curl" is done reading it)

+ 3 - 4
test/tests/php-fpm-hello-web/run.sh

@@ -25,10 +25,6 @@ EOD
 cid="$(docker run -d "$serverImage")"
 trap "docker rm -vf $cid > /dev/null" EXIT
 
-# RACY TESTS ARE RACY
-sleep 1
-# TODO find a cleaner solution to this, similar to what we do in mysql-basics
-
 fcgi-request() {
 	local method="$1"
 
@@ -48,6 +44,9 @@ fcgi-request() {
 		-bind -connect fpm:9000
 }
 
+# wait until ready
+. "$dir/../../retry.sh" --tries 30 'fcgi-request GET /index.php' > /dev/null 2>&1
+
 # Check that we can request /index.php with no params
 [ -n "$(fcgi-request GET "/index.php")" ]
 

+ 0 - 31
test/tests/wordpress-fpm-run/nginx-default.conf

@@ -1,31 +0,0 @@
-# adapted from https://gist.github.com/md5/d9206eacb5a0ff5d6be0#file-wordpress-fpm-conf
-
-server {
-	listen 80;
-	root /var/www/html;
-
-	client_max_body_size 0;
-
-	index index.php;
-
-	location / {
-		try_files $uri $uri/ /index.php?$args;
-	}
-
-	rewrite /wp-admin$ $scheme://$host$uri/ permanent;
-
-	location ~ [^/]\.php(/|$) {
-		fastcgi_split_path_info ^(.+?\.php)(/.*)$;
-		if (!-f $document_root$fastcgi_script_name) {
-			return 404;
-		}
-
-		include fastcgi_params;
-		fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
-		#fastcgi_param PATH_INFO       $fastcgi_path_info;
-		#fastcgi_param PATH_TRANSLATED /var/www/html/$fastcgi_path_info;
-
-		fastcgi_pass fpm:9000;
-		fastcgi_index index.php;
-	}
-}

+ 28 - 21
test/tests/wordpress-fpm-run/run.sh

@@ -3,43 +3,50 @@ set -eo pipefail
 
 dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
 
-# since we have curl in the php image, we'll use that
-clientImage="$1"
+image="$1"
 
 # Build a client image with cgi-fcgi for testing
-nginxImage="$("$dir/../image-name.sh" librarytest/wordpress-fpm-run-nginx "$1")"
-"$dir/../docker-build.sh" "$dir" "$nginxImage" <<EOD
-FROM nginx:alpine
-COPY dir/nginx-default.conf /etc/nginx/conf.d/default.conf
-EOD
+clientImage='librarytest/wordpress-fpm-run:fcgi-client'
+docker build -t "$clientImage" - > /dev/null <<'EOF'
+FROM debian:stretch-slim
+
+RUN set -x && apt-get update && apt-get install -y libfcgi0ldbl && rm -rf /var/lib/apt/lists/*
+
+ENTRYPOINT ["cgi-fcgi"]
+EOF
 
 mysqlImage='mysql:5.7'
-serverImage="$1"
 
 # Create an instance of the container-under-test
 mysqlCid="$(docker run -d -e MYSQL_ROOT_PASSWORD="test-$RANDOM-password-$RANDOM-$$" "$mysqlImage")"
 trap "docker rm -vf $mysqlCid > /dev/null" EXIT
-cid="$(docker run -d --link "$mysqlCid":mysql "$serverImage")"
+cid="$(docker run -d --link "$mysqlCid":mysql "$image")"
 trap "docker rm -vf $cid $mysqlCid > /dev/null" EXIT
-nginxCid="$(docker run -d --link "$cid":fpm --volumes-from "$cid" "$nginxImage")"
-trap "docker rm -vf $nginxCid $cid $mysqlCid > /dev/null" EXIT
 
-_request() {
+fcgi-request() {
 	local method="$1"
-	shift
-
-	local url="${1#/}"
-	shift
 
-	docker run --rm --link "$nginxCid":nginx "$clientImage" \
-		curl -fsL -X"$method" "$@" "http://nginx/$url"
+	local url="$2"
+	local queryString=
+	if [[ "$url" == *\?* ]]; then
+		queryString="${url#*\?}"
+		url="${url%%\?*}"
+	fi
+
+	docker run --rm -i --link "$cid":fpm \
+		-e REQUEST_METHOD="$method" \
+		-e SCRIPT_NAME="$url" \
+		-e SCRIPT_FILENAME=/var/www/html/"${url#/}" \
+		-e QUERY_STRING="$queryString" \
+		"$clientImage" \
+		-bind -connect fpm:9000
 }
 
 # Make sure that PHP-FPM is listening and ready
-. "$dir/../../retry.sh" --tries 30 '_request GET / --output /dev/null'
+. "$dir/../../retry.sh" --tries 30 'fcgi-request GET /index.php' > /dev/null 2>&1
 # (give it a bit long since it won't start until MySQL is started and ready)
 
-# Check that we can request / and that it contains the word "setup" somewhere
+# index.php redirects to wp-admin/install.php, check that it contains the word "setup" somewhere
 # <form id="setup" method="post" action="?step=1"><label class='screen-reader-text' for='language'>Select a default language</label>
-_request GET '/' |tac|tac| grep -iq setup
+fcgi-request GET '/wp-admin/install.php' |tac|tac| grep -iq setup
 # (without "|tac|tac|" we get "broken pipe" since "grep" closes the pipe before "curl" is done reading it)