Add regression test for auto_failback
authorTakuma Hoshiai <hoshiai@sraoss.co.jp>
Mon, 22 Jul 2019 08:05:41 +0000 (17:05 +0900)
committerTakuma Hoshiai <hoshiai@sraoss.co.jp>
Mon, 22 Jul 2019 08:05:41 +0000 (17:05 +0900)
src/test/regression/tests/027.auto_failback/.gitignore [new file with mode: 0644]
src/test/regression/tests/027.auto_failback/test.sh [new file with mode: 0755]

diff --git a/src/test/regression/tests/027.auto_failback/.gitignore b/src/test/regression/tests/027.auto_failback/.gitignore
new file mode 100644 (file)
index 0000000..f937fcb
--- /dev/null
@@ -0,0 +1 @@
+testdir/
diff --git a/src/test/regression/tests/027.auto_failback/test.sh b/src/test/regression/tests/027.auto_failback/test.sh
new file mode 100755 (executable)
index 0000000..e09820c
--- /dev/null
@@ -0,0 +1,98 @@
+#!/usr/bin/env bash
+#-------------------------------------------------------------------
+# test script for auto failback
+#
+source $TESTLIBS
+TESTDIR=testdir
+PG_CTL=$PGBIN/pg_ctl
+PSQL="$PGBIN/psql"
+
+rm -fr $TESTDIR
+mkdir $TESTDIR
+cd $TESTDIR
+
+# create test environment
+echo -n "creating test environment..."
+$PGPOOL_SETUP -m s -n 2 || exit 1
+echo "done."
+
+echo "auto_failback = on" >> etc/pgpool.conf
+echo "auto_failback_interval = 60" >> etc/pgpool.conf
+echo "sr_check_period = 2" >> etc/pgpool.conf
+echo "health_check_period = 2" >> etc/pgpool.conf
+
+source ./bashrc.ports
+
+export PGPORT=$PGPOOL_PORT
+
+
+./startall
+wait_for_pgpool_startup
+
+$PSQL -c "show pool_nodes" test |grep down
+if [ $? = 0 ];then
+       ./shutdownall
+       exit 1
+fi
+
+# trigger failover on node 1
+$PG_CTL -D data1 -w -m f stop
+wait_for_pgpool_startup
+echo "backend node 1 is stooped"
+
+$PSQL -c "show pool_nodes" test |grep down
+if [ $? != 0 ];then
+       ./shutdownall
+       exit 1
+fi
+
+# node 1 restart
+$PG_CTL -D data1 -w -m f start
+echo "backend node 1 is restarted"
+sleep 10;
+
+# check auto_failback is succuess
+$PSQL -c "show pool_nodes" test |grep down
+if [ $? = 0 ];then
+       ./shutdownall
+       exit 1
+fi
+echo "auto_failback is success"
+
+# check auto_failback_interval
+
+echo `date` ":test auto_failback_interval"
+# trigger failover on node 1
+$PG_CTL -D data1 -w -m f stop > /dev/null
+wait_for_pgpool_startup
+echo `date` ":backend node 1 is stooped"
+$PSQL -c "show pool_nodes" test |grep down
+if [ $? != 0 ];then
+       ./shutdownall
+       exit 1
+fi
+$PG_CTL -D data1 -w -m f start > /dev/null
+echo `date` ":backend node 1 is restarted"
+
+echo `date` ":sleep 20[sec]"
+sleep 20;
+$PSQL -c "show pool_nodes" test |grep down
+if [ $? != 0 ];then
+       ./shutdownall
+       exit 1
+fi
+echo `date` ":backend node staus is still detached"
+
+echo `date` ":sleep 40[sec]"
+sleep 40;
+$PSQL -c "show pool_nodes" test |grep down
+if [ $? != 0 ];then
+       ./shutdownall
+       exit 1
+fi
+echo `date` ":the time of auto_failback_intervall passed and auto_failback is success."
+
+
+./shutdownall
+
+exit 0