The idea behind it is
- create required pgpool cluster (pgpool + PostgreSQL instances) by using pgpool_setup
- each test case is a simple shell script
- each script returns 0 or 1 according to the test result
$ sh regress.sh
testing 001.load_balance...ok.
testing 002.native_replication...ok.
testing 003.failover...ok.
testing 050.bug58...ok.
testing 051.bug60...ok.
testing 052.do_query...ok.
testing 053.insert_lock_hangs...ok.
out of 7 ok:7 failed:0
For example, "001.load_balance" checks whether load balancing is working against 2 node native replication or streaming replication cluster by using this simple script:
#! /bin/sh
#-------------------------------------------------------------------
# test script for load balancing.
#
source $TESTLIBS
TESTDIR=testdir
for mode in s r
do
rm -fr $TESTDIR
mkdir $TESTDIR
cd $TESTDIR
# create test environment
echo -n "creating test environment..."
sh $PGPOOL_SETUP -m $mode -n 2 || exit 1
echo "done."
source ./bashrc.ports
echo "backend_weight0 = 0" >> etc/pgpool.conf
echo "backend_weight1 = 1" >> etc/pgpool.conf
echo "black_function_list = 'f1'" >> etc/pgpool.conf
./startall
export PGPORT=$PGPOOL_PORT
wait_for_pgpool_startup
psql test <<EOF
CREATE TABLE t1(i INTEGER);
CREATE FUNCTION f1(INTEGER) returns INTEGER AS 'SELECT \$1' LANGUAGE SQL;
SELECT * FROM t1; -- this load balances
SELECT f1(1); -- this does not load balance
EOF
# check if simle load balance worked
fgrep "SELECT * FROM t1;" log/pgpool.log |grep "DB node id: 1">/dev/null 2>&1
if [ $? != 0 ];then
# expected result not found
./shutdownall
exit 1
fi
# check if black function list worked
fgrep "SELECT f1(1);" log/pgpool.log |grep "DB node id: 0">/dev/null 2>&1
if [ $? != 0 ];then
# expected result not found
./shutdownall
exit 1
fi
echo "white_function_list = 'f1'" >> etc/pgpool.conf
echo "black_function_list = ''" >> etc/pgpool.conf
./pgpool_reload
psql test <<EOF
SELECT f1(1); -- this does load balance
EOF
# check if white function list worked
fgrep "SELECT f1(1);" log/pgpool.log |grep "DB node id: 1">/dev/null 2>&1
if [ $? != 0 ];then
# expected result not found
./shutdownall
exit 1
fi
./shutdownall
cd ..
done
exit 0
I hope pgpool developers would add more test cases.
No comments:
Post a Comment