From 41ac644a3df185d69931c7d8fa1f74bbd27a423e Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Sun, 1 Sep 2019 12:20:33 +0900 Subject: [PATCH] Add regression test for enable_consensus_with_half_votes. This is a test for 2, 3, 4 watchdog nodes, with enable_consensus_with_half_votes is on/off cases. In each test, half of watchdog nodes are shut down and check to see if quorum exists (or on the edge for even number nodes). --- .../test.sh | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100755 src/test/regression/tests/028.watchdog_enable_consensus_with_half_of_the_votes/test.sh diff --git a/src/test/regression/tests/028.watchdog_enable_consensus_with_half_of_the_votes/test.sh b/src/test/regression/tests/028.watchdog_enable_consensus_with_half_of_the_votes/test.sh new file mode 100755 index 000000000..44d58917f --- /dev/null +++ b/src/test/regression/tests/028.watchdog_enable_consensus_with_half_of_the_votes/test.sh @@ -0,0 +1,141 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------- +# test script for enable_consensus_with_half_votes +# +source $TESTLIBS +TESTDIR=testdir +PSQL=$PGBIN/psql + +# set enable_consensus_with_half_votes to on or off depending on the $val arg. +function set_param +{ + n=0 + while [ $n -lt $nodes ] + do + echo "enable_consensus_with_half_votes = $val" >> pgpool$n/etc/pgpool.conf + n=`expr $n + 1` + done +} + +# wait for watchdog starting up by looking for "lifecheck started" in +# the pgpool.log. argument: $log: absolute path to the pgpool.log. +function wait_for_watchdog_startup +{ + while : + do + grep "lifecheck started" $log >/dev/null + if [ $? = 0 ];then + break; + fi + sleep 1 + done +} + +# retun 0 if quorum exists. +function quorum_exists +{ + pcp_watchdog_info -v -w -p $PCP_PORT |grep QUORUM|egrep 'EXIST|EDGE'>/dev/null +} + +# shutdown half of nodes for even total number of nodes. +# shutdown (n + 1)/2 nodes for even number of total nodes n. +# args: nodes: number of total nodes +function shutdown_nodes +{ + cdir=`pwd` + n=`expr \( $nodes + 1 \) / 2` + while [ $n -gt 0 ] + do + cd $dir/$TESTDIR/pgpool$n + echo "shutdown node pgpool$n" + ./shutdownall + sleep 1 + n=`expr $n - 1` + done + cd $cdir +} + +# return 0 fi nodes is even +function nodes_even +{ + test `expr $nodes % 2` = 0 +} + +#-----------------------------------------------------------------== +dir=`pwd` + +failed=false +export CHECK_TIME_WAIT=true + +for nodes in 2 3 4 +do + cd $dir + rm -fr $TESTDIR + mkdir $TESTDIR + cd $TESTDIR + + $WATCHDOG_SETUP -wn $nodes || exit 1 + + val="off" + set_param + + ./startall + + cd pgpool0 + source ./bashrc.ports + export PGPORT=$PGPOOL_PORT + cd .. + + echo -n "waiting for watchdog node 0 starting up... " + log=$dir/$TESTDIR/pgpool0/log/pgpool.log + wait_for_watchdog_startup $log + echo "done." + + echo "=== Testing total nodes: $nodes. enable_consensus_with_half_of_the_votes: $val ===" + shutdown_nodes + + if quorum_exists + then + echo "Quorum exists. Test failed" + failed=true + else + echo "Quorum does not exist. Test succeeded" + fi + + ./shutdownall + sleep 1 + val="on" + set_param + ./startall + wait_for_watchdog_startup $log + + echo "Testing total nodes: $nodes. enable_consensus_with_half_of_the_votes: $val" + shutdown_nodes + + if quorum_exists + then + if nodes_even + then + echo "Quorum exists. Test succeeded" + else + echo "Quorum exists. Test failed" + failed=true + fi + else + if nodes_even + then + echo "Quorum does not exist. Test failed" + failed=true + else + echo "Quorum does not exist. Test succeeded" + fi + fi + + ./shutdownall + sleep 10 +done + +if [ $failed = "true" ];then + exit 1 +fi +exit 0 -- 2.39.5