Enhance extended query test.
authorTatsuo Ishii <ishii@postgresql.org>
Mon, 19 Feb 2018 05:19:30 +0000 (14:19 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Mon, 19 Feb 2018 05:19:30 +0000 (14:19 +0900)
Add extra_scripts directory to include extra scripts to be executed
after main test script (tests) run.  Currently only scripts for
parse-before-bind.data parse-before-bind-2.data exist so that the test
confirm the load balancing behavior.

Also some tests are fixed so that they can run individually in that a
table for testing is dropped at the end of the test and test results
are not affected by the existence of the table.

12 files changed:
src/test/extended-query-test/README
src/test/extended-query-test/expected/parse-before-bind-2.data
src/test/extended-query-test/expected/parse-before-bind.data
src/test/extended-query-test/expected/query-cache-notrans.data
src/test/extended-query-test/expected/query-cache.data
src/test/extended-query-test/extra_scripts/parse-before-bind-2.data [new file with mode: 0755]
src/test/extended-query-test/extra_scripts/parse-before-bind.data [new file with mode: 0755]
src/test/extended-query-test/test.sh
src/test/extended-query-test/tests/parse-before-bind-2.data
src/test/extended-query-test/tests/parse-before-bind.data
src/test/extended-query-test/tests/query-cache-notrans.data
src/test/extended-query-test/tests/query-cache.data

index 506e7876c5d642968787e3bc62b962d53145fa01..6c62ec39308d5a3bc08742a6bf3cce28df97ee69 100644 (file)
@@ -3,7 +3,7 @@ https://github.com/tatsuo-ishii/pgproto
 
 Overview:
 
-The objective the test suites is testing behaviors of Pgpool-II
+The objective of the test suites is testing behaviors of Pgpool-II
 running in streaming replication with extended queries. The reason
 pgproto used here is, it is very difficult to implement that kind of
 tests using standard drivers such as libpq and Java because no low
@@ -24,13 +24,27 @@ regular expressions.
 
 How to add tests:
 
-Add pgproto data under "tests" directory. Also you need to add
-expected output of pgproto to "expected" directory. The file name must
-be identical to the file name added to tests directory. Note that
-source files lines like "1186" below
-<= BE ErrorResponse(S ERROR V ERROR C 42P01 M relation "non_existsing_table" does not exist P 15 F parse_relation.c L 1186 R parserOpenTable )
-will be replaced with "xxx" to avoid the source code version differences.
+Add pgproto data under "tests" directory. File names do not matter. By
+a historical reason, ".data" is used but you can choose arbitrary
+names. Next you need to add expected output of pgproto to "expected"
+directory. The file name must be identical to the file name added to
+the tests directory. Note that source files lines like "1186" below <=
+BE ErrorResponse(S ERROR V ERROR C 42P01 M relation
+"non_existsing_table" does not exist P 15 F parse_relation.c L 1186 R
+parserOpenTable ) will be replaced with "xxx" to avoid the source code
+version differences.
 
 If you need to add special directives to pgpool.conf, include those
 configuration directives to the pgproto data starting with "##". You
 can see examples in parse-before-bind.data.
+
+Optional tests:
+
+An optional extra test script can be added to "extra_scripts"
+directory. The file name must be identical to the file name added to
+the tests directory. Those files must be executable and are executed
+after pgproto run. The test only succeeds when both pgproto test is ok
+and the extra script returns 0 status. Typical usage of the script is
+checking the load balance behavior by looking at Pgpool-II log. Note
+that the log file name is exported as an environment variable
+"$PGPOOLLOG".
index 9883c7e7dd706a1361ad682c0ae6ab05b6e83374..434b43324ac0ad3aad4f86f0b0362769667d10dc 100644 (file)
@@ -1,5 +1,5 @@
 FE=> Query(query="DROP TABLE IF EXISTS pgproto_test1")
-<= BE NoticeResponse(S NOTICE V NOTICE C 00000 M table "pgproto_test1" does not exist, skipping F tablecmds.c L 764 R DropErrorMsgNonExistent )
+<= BE NoticeResponse(S NOTICE V NOTICE C 00000 M table "pgproto_test1" does not exist, skipping F tablecmds.c L 914 R DropErrorMsgNonExistent )
 <= BE CommandComplete(DROP TABLE)
 <= BE ReadyForQuery(I)
 FE=> Query(query="CREATE TABLE pgproto_test1(i INT)")
@@ -40,4 +40,7 @@ FE=> Sync
 <= BE CommandComplete(COMMIT)
 <= BE CloseComplete
 <= BE ReadyForQuery(I)
+FE=> Query(query="DROP TABLE pgproto_test1")
+<= BE CommandComplete(DROP TABLE)
+<= BE ReadyForQuery(I)
 FE=> Terminate
index e5f26ac692c70f02f7917ff885226955fea6e82c..48060c5605b6980211ef0dcd2504c879d6a3c94f 100644 (file)
@@ -1,4 +1,5 @@
 FE=> Query(query="DROP TABLE IF EXISTS pgproto_test1")
+<= BE NoticeResponse(S NOTICE V NOTICE C 00000 M table "pgproto_test1" does not exist, skipping F tablecmds.c L 914 R DropErrorMsgNonExistent )
 <= BE CommandComplete(DROP TABLE)
 <= BE ReadyForQuery(I)
 FE=> Query(query="CREATE TABLE pgproto_test1(i INT)")
@@ -39,4 +40,7 @@ FE=> Sync
 <= BE CommandComplete(COMMIT)
 <= BE CloseComplete
 <= BE ReadyForQuery(I)
+FE=> Query(query="DROP TABLE pgproto_test1")
+<= BE CommandComplete(DROP TABLE)
+<= BE ReadyForQuery(I)
 FE=> Terminate
index 8b6eef9148eb791ca6a82e8501d0a0893391beae..453bcf6b451fb0b4c72719548ad6fd06bbcda01b 100644 (file)
@@ -1,4 +1,5 @@
 FE=> Query(query="DROP TABLE IF EXISTS pgproto_test1")
+<= BE NoticeResponse(S NOTICE V NOTICE C 00000 M table "pgproto_test1" does not exist, skipping F tablecmds.c L 914 R DropErrorMsgNonExistent )
 <= BE CommandComplete(DROP TABLE)
 <= BE ReadyForQuery(I)
 FE=> Query(query="CREATE TABLE pgproto_test1(i INT)")
@@ -33,4 +34,7 @@ FE=> Sync
 <= BE CommandComplete(SELECT 1)
 <= BE CloseComplete
 <= BE ReadyForQuery(I)
+FE=> Query(query="DROP TABLE pgproto_test1")
+<= BE CommandComplete(DROP TABLE)
+<= BE ReadyForQuery(I)
 FE=> Terminate
index 8b08fe34abd0d5bf57a4ba740ae9e8791dfa117e..324afff6af7dd94c0fe37099e95e88cf1589cac3 100644 (file)
@@ -1,4 +1,5 @@
 FE=> Query(query="DROP TABLE IF EXISTS pgproto_test1")
+<= BE NoticeResponse(S NOTICE V NOTICE C 00000 M table "pgproto_test1" does not exist, skipping F tablecmds.c L 914 R DropErrorMsgNonExistent )
 <= BE CommandComplete(DROP TABLE)
 <= BE ReadyForQuery(I)
 FE=> Query(query="CREATE TABLE pgproto_test1(i INT)")
@@ -55,4 +56,7 @@ FE=> Sync
 <= BE CommandComplete(SELECT 1)
 <= BE CloseComplete
 <= BE ReadyForQuery(I)
+FE=> Query(query="DROP TABLE pgproto_test1")
+<= BE CommandComplete(DROP TABLE)
+<= BE ReadyForQuery(I)
 FE=> Terminate
diff --git a/src/test/extended-query-test/extra_scripts/parse-before-bind-2.data b/src/test/extended-query-test/extra_scripts/parse-before-bind-2.data
new file mode 100755 (executable)
index 0000000..436f85c
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+
+set 1 0 0      # expected results: Parse:1 Parse:0 Execute: 0
+grep "SELECT 1" $PGPOOLLOG |awk '{print $9}' | while read node
+do
+    if [ $1 -ne $node ]
+    then
+       echo "expected: $1 result: $node"
+       exit 99
+    fi
+    shift
+done
+
+if [ $? = 99 ]
+then
+   exit 1
+fi
+
+exit 0
+   
diff --git a/src/test/extended-query-test/extra_scripts/parse-before-bind.data b/src/test/extended-query-test/extra_scripts/parse-before-bind.data
new file mode 100755 (executable)
index 0000000..436f85c
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+
+set 1 0 0      # expected results: Parse:1 Parse:0 Execute: 0
+grep "SELECT 1" $PGPOOLLOG |awk '{print $9}' | while read node
+do
+    if [ $1 -ne $node ]
+    then
+       echo "expected: $1 result: $node"
+       exit 99
+    fi
+    shift
+done
+
+if [ $? = 99 ]
+then
+   exit 1
+fi
+
+exit 0
+   
index 2260774950de08875f777f71a874cb85894cd123..b8bff3220db475f278f212a0c5bc7f49605a6368 100755 (executable)
@@ -9,6 +9,8 @@ PGPROTO=/usr/local/bin/pgproto
 
 testdir=`pwd`/tests
 expected=`pwd`/expected
+extra_scripts=`pwd`/extra_scripts
+export PGPOOLLOG=`pwd`/testdata/log/pgpool.log
 results=`pwd`/results
 rm -f $results/*
 test ! -d $results && mkdir $results
@@ -74,8 +76,25 @@ do
            diff -N $expected/$i $results/$i >> $diffs
            failcnt=`expr $failcnt + 1`
        else
-           echo "ok."
-           okcnt=`expr $okcnt + 1`
+           extra_fail=0
+           # excute extra scripts if exists.
+           if [ -x $extra_scripts/$i ]
+           then
+               $extra_scripts/$i > $results/$i.extra 2>&1
+
+               if [ $? != 0 ]
+               then
+                   echo "extra test failed."
+                   extra_fail=1
+                   failcnt=`expr $failcnt + 1`
+               fi
+           fi
+
+           if [ $extra_fail = 0 ]
+           then
+               echo "ok."
+               okcnt=`expr $okcnt + 1`
+           fi
        fi
        rm expected_tmp results_tmp
     fi
index 205159dc1ef20863573a9c334fa06687e792f46e..22170d9dfb7bf444c15012aab5fbf30690ec4b01 100644 (file)
@@ -1,11 +1,14 @@
 # Test data for bug271.
 # In an explicit transaction, SELECT is parsed, DML issued, same SELECT/bind issued.
-# In this case Pgpool-II should parse resend to primary node.
+# In this case Pgpool-II should resend parse message to primary node.
 # Similar to pgproto.data but in this case SELECT uses "S1" statement.
 # As of 2017/2/14, this fails.
 # <= BE ErrorResponse(S ERROR C XX000 M unable to bind D cannot get parse message "S1" F pool_proto_modules.c L 1317 )
 # Moreover, Pgpool-II does not close the idle connection.
 
+##backend_weight0 = 0
+##backend_weight1 = 1
+
 # Create test table
 'Q'    "DROP TABLE IF EXISTS pgproto_test1"
 'Y'
@@ -39,4 +42,9 @@
 'C'    'S'     "S1"
 'S'
 'Y'
+
+# DROP test table
+'Q'    "DROP TABLE pgproto_test1"
+'Y'
+
 'X'
index 38f6f0446f0548ef9ca6942b463596c718e40d37..f5d41941617caaa951b50acf54ab37ee44d1be49 100644 (file)
@@ -40,4 +40,9 @@
 'C'    'S'     "S1"
 'S'
 'Y'
+
+# DROP test table
+'Q'    "DROP TABLE pgproto_test1"
+'Y'
+
 'X'
index 3879b7378be6af5f4038a0857e1b7ef1492ce3cd..1ed6c36c9fc40de9fc02cd17fa2e3e63b460abde 100644 (file)
@@ -26,4 +26,9 @@
 
 'S'
 'Y'
+
+# DROP test table
+'Q'    "DROP TABLE pgproto_test1"
+'Y'
+
 'X'
index 7150c72055363c20590d078496adfafa6dbec30f..9973f22ef7aab6966282f8237d7cf872606f664b 100644 (file)
@@ -45,4 +45,9 @@
 
 'S'
 'Y'
+
+# DROP test table
+'Q'    "DROP TABLE pgproto_test1"
+'Y'
+
 'X'