Add new regression test for node 0 not being primary.
authorTatsuo Ishii <ishii@postgresql.org>
Tue, 27 Feb 2018 05:04:20 +0000 (14:04 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Tue, 27 Feb 2018 05:04:20 +0000 (14:04 +0900)
src/test/regression/tests/016.node_0_is_not_primary/test.sh [new file with mode: 0755]

diff --git a/src/test/regression/tests/016.node_0_is_not_primary/test.sh b/src/test/regression/tests/016.node_0_is_not_primary/test.sh
new file mode 100755 (executable)
index 0000000..6778416
--- /dev/null
@@ -0,0 +1,63 @@
+#!/usr/bin/env bash
+#-------------------------------------------------------------------
+# test script for the case when node 0 is not primary.
+#
+source $TESTLIBS
+TESTDIR=testdir
+PSQL=$PGBIN/psql
+PG_CTL=$PGBIN/pg_ctl
+export PGDATABASE=test
+
+for mode in s
+do
+       rm -fr $TESTDIR
+       mkdir $TESTDIR
+       cd $TESTDIR
+
+       echo "===== testing mode: $mode ======"
+
+       # create test environment
+       echo -n "creating test environment..."
+       $PGPOOL_SETUP -m $mode -n 2 || exit 1
+       echo "done."
+
+       source ./bashrc.ports
+
+       ./startall
+
+       export PGPORT=$PGPOOL_PORT
+
+       wait_for_pgpool_startup
+
+       echo "Swapping the role of node 0 and node 1..."
+       $PG_CTL -D data0 -m f stop
+       wait_for_pgpool_startup
+       $PGPOOL_INSTALL_DIR/bin/pcp_recovery_node -w -h localhost -p $PCP_PORT 0
+       wait_for_pgpool_startup
+       echo "Swapping the role of node 0 and node 1...done."
+       $PSQL -c "show pool_nodes"
+
+       # make sure that node 1 is master/primary
+       test `$PSQL -c "show pool_nodes"|egrep "primary|master"|awk '{print $1}'` = 1 &&
+           test `$PSQL -c "show pool_nodes"|egrep "primary|master"|awk '{print $7}'` = "up"
+       if [ $? != 0 ]
+       then
+           echo "node 1 is not primary or master"
+           ./shutdownall
+           exit 1
+       fi
+
+       # try to issue write query
+       $PSQL -c "create table t1(i int)"
+       if [ $? != 0 ]
+       then
+           echo "write query failed"
+           ./shutdownall
+           exit 1
+       fi
+
+       ./shutdownall
+       cd ..
+done
+
+exit 0