system-test: clear cache; simpler init

* always run with a clean cache
 * in the future we should structure the tests so they run twice, once with a clean cache and then again with a populated one, but for now a clean cache should catch more bugs
* stop requiring a file cache path for tests; just use
* fix exit codes to match documentation at the top of the file: 1 is a test failure, 2 is bad args

Squash-merge of my #198.
This commit is contained in:
Jeff Kaufman
2013-03-29 11:37:17 -04:00
parent b25150effe
commit 768ba6a64f
4 changed files with 31 additions and 32 deletions
+1 -1
View File
@@ -1 +1 @@
test/pagespeed_test.conf
test/tmp
+1 -2
View File
@@ -213,13 +213,12 @@ Then run:
primary_port \
secondary_port \
mod_pagespeed_dir \
file_cache_path \
nginx_executable_path
For example:
$ test/nginx_system_test.sh 8050 8051 /path/to/mod_pagespeed \
/path/to/ngx_pagespeed_cache /path/to/sbin/nginx
/path/to/sbin/nginx
This should print out a lot of lines like:
+23 -18
View File
@@ -25,25 +25,21 @@
# Exits with status 2 if command line args are wrong.
#
# Usage:
# ./ngx_system_test.sh primary_port secondary_port \
# mod_pagespeed_dir file_cache_path
# for example:
# ./ngx_system_test.sh 8050 8051 \
# /path/to/mod_pagespeed \
# /path.to/ngx_pagespeed_cache
# ./ngx_system_test.sh primary_port secondary_port mod_pagespeed_dir
# Example:
# ./ngx_system_test.sh 8050 8051 /path/to/mod_pagespeed
#
if [ "$#" -ne 5 ] ; then
if [ "$#" -ne 4 ] ; then
echo "Usage: $0 primary_port secondary_port mod_pagespeed_dir"
echo " file_cache_path nginx_executable"
exit 1
echo " nginx_executable"
exit 2
fi
PRIMARY_PORT="$1"
SECONDARY_PORT="$2"
MOD_PAGESPEED_DIR="$3"
FILE_CACHE_PATH="$4"
NGINX_EXECUTABLE="$5"
NGINX_EXECUTABLE="$4"
PRIMARY_HOSTNAME="localhost:$PRIMARY_PORT"
SECONDARY_HOSTNAME="localhost:$SECONDARY_PORT"
@@ -54,7 +50,7 @@ SERVER_ROOT="$MOD_PAGESPEED_DIR/src/install/"
# them.
function handle_failure_simple() {
echo "FAIL"
exit 2
exit 1
}
function check_simple() {
echo " check" "$@"
@@ -67,9 +63,19 @@ function check_not_simple() {
this_dir="$( cd $(dirname "$0") && pwd)"
# stop nginx
killall nginx
TEST_TMP="$this_dir/tmp"
rm -r "$TEST_TMP"
check_simple mkdir "$TEST_TMP"
FILE_CACHE="$TEST_TMP/file-cache/"
check_simple mkdir "$FILE_CACHE"
# set up the config file for the test
PAGESPEED_CONF="$this_dir/pagespeed_test.conf"
PAGESPEED_CONF_TEMPLATE="$PAGESPEED_CONF.template"
PAGESPEED_CONF="$TEST_TMP/pagespeed_test.conf"
PAGESPEED_CONF_TEMPLATE="$this_dir/pagespeed_test.conf.template"
# check for config file template
check_simple test -e "$PAGESPEED_CONF_TEMPLATE"
# create PAGESPEED_CONF by substituting on PAGESPEED_CONF_TEMPLATE
@@ -78,7 +84,8 @@ This file is automatically generated from $PAGESPEED_CONF_TEMPLATE"
by nginx_system_test.sh; don't edit here."
EOF
cat $PAGESPEED_CONF_TEMPLATE \
| sed 's#@@FILE_CACHE_PATH@@#'"$FILE_CACHE_PATH/"'#' \
| sed 's#@@TEST_TMP@@#'"$TEST_TMP/"'#' \
| sed 's#@@FILE_CACHE@@#'"$FILE_CACHE/"'#' \
| sed 's#@@SERVER_ROOT@@#'"$SERVER_ROOT"'#' \
| sed 's#@@PRIMARY_PORT@@#'"$PRIMARY_PORT"'#' \
| sed 's#@@SECONDARY_PORT@@#'"$SECONDARY_PORT"'#' \
@@ -86,9 +93,7 @@ cat $PAGESPEED_CONF_TEMPLATE \
# make sure we substituted all the variables
check_not_simple grep @@ $PAGESPEED_CONF
# restart nginx with new config
killall nginx
sleep .1
# start nginx with new config
check_simple "$NGINX_EXECUTABLE" -c "$PAGESPEED_CONF"
# run generic system tests
+6 -11
View File
@@ -1,20 +1,14 @@
# nginx_system_test.sh makes a few substitutions to this file to generate
# pagespeed_test.conf
# nginx_system_test.sh makes a few substitutions to pagespeed_test.conf.template
# file to generate @@TEST_TMP@@/pagespeed_test.conf
#user nobody;
worker_processes 1;
# for debugging
#daemon off;
#master_process off;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
error_log logs/error.log debug;
#pid logs/nginx.pid;
error_log "@@TEST_TMP@@/error.log" debug;
pid "@@TEST_TMP@@/nginx.pid";
events {
worker_connections 1024;
@@ -22,13 +16,14 @@ events {
http {
access_log "@@TEST_TMP@@/access.log";
root "@@SERVER_ROOT@@";
server {
listen @@PRIMARY_PORT@@;
server_name localhost;
pagespeed FileCachePath "@@FILE_CACHE_PATH@@";
pagespeed FileCachePath "@@FILE_CACHE@@";
# uncomment the following two lines if you're testing memcached
#pagespeed MemcachedServers "localhost:11211";