pgpool2.git / summary / log / commit / refs

commit    6701211b8ae556a568de79a1b4b7fe2cfbd19d31
Author:   Tatsuo Ishii <ishii@postgresql.org>
Date:     Mon Feb 19 05:19:30 2018 +0000

    Enhance extended query test.
    
    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.


src/test/extended-query-test/README | 28 ++++++++++++++++------ .../expected/parse-before-bind-2.data | 5 +++- .../expected/parse-before-bind.data | 4 ++++ .../expected/query-cache-notrans.data | 4 ++++ .../extended-query-test/expected/query-cache.data | 4 ++++ .../extra_scripts/parse-before-bind-2.data | 20 ++++++++++++++++ .../extra_scripts/parse-before-bind.data | 20 ++++++++++++++++ src/test/extended-query-test/test.sh | 23 ++++++++++++++++-- .../tests/parse-before-bind-2.data | 10 +++++++- .../tests/parse-before-bind.data | 5 ++++ .../tests/query-cache-notrans.data | 5 ++++ .../extended-query-test/tests/query-cache.data | 5 ++++ 12 files changed, 122 insertions(+), 11 deletions(-) diff --git a/src/test/extended-query-test/README b/src/test/extended-query-test/README index 506e7876c..6c62ec393 100644 --- a/src/test/extended-query-test/README +++ b/src/test/extended-query-test/README @@ -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". diff --git a/src/test/extended-query-test/expected/parse-before-bind-2.data b/src/test/extended-query-test/expected/parse-before-bind-2.data index 9883c7e7d..434b43324 100644 --- a/src/test/extended-query-test/expected/parse-before-bind-2.data +++ b/src/test/extended-query-test/expected/parse-before-bind-2.data @@ -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 diff --git a/src/test/extended-query-test/expected/parse-before-bind.data b/src/test/extended-query-test/expected/parse-before-bind.data index e5f26ac69..48060c560 100644 --- a/src/test/extended-query-test/expected/parse-before-bind.data +++ b/src/test/extended-query-test/expected/parse-before-bind.data @@ -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 diff --git a/src/test/extended-query-test/expected/query-cache-notrans.data b/src/test/extended-query-test/expected/query-cache-notrans.data index 8b6eef914..453bcf6b4 100644 --- a/src/test/extended-query-test/expected/query-cache-notrans.data +++ b/src/test/extended-query-test/expected/query-cache-notrans.data @@ -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 diff --git a/src/test/extended-query-test/expected/query-cache.data b/src/test/extended-query-test/expected/query-cache.data index 8b08fe34a..324afff6a 100644 --- a/src/test/extended-query-test/expected/query-cache.data +++ b/src/test/extended-query-test/expected/query-cache.data @@ -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 index 000000000..436f85c08 --- /dev/null +++ b/src/test/extended-query-test/extra_scripts/parse-before-bind-2.data @@ -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 index 000000000..436f85c08 --- /dev/null +++ b/src/test/extended-query-test/extra_scripts/parse-before-bind.data @@ -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/test.sh b/src/test/extended-query-test/test.sh index 226077495..b8bff3220 100755 --- a/src/test/extended-query-test/test.sh +++ b/src/test/extended-query-test/test.sh @@ -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 diff --git a/src/test/extended-query-test/tests/parse-before-bind-2.data b/src/test/extended-query-test/tests/parse-before-bind-2.data index 205159dc1..22170d9df 100644 --- a/src/test/extended-query-test/tests/parse-before-bind-2.data +++ b/src/test/extended-query-test/tests/parse-before-bind-2.data @@ -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' diff --git a/src/test/extended-query-test/tests/parse-before-bind.data b/src/test/extended-query-test/tests/parse-before-bind.data index 38f6f0446..f5d419416 100644 --- a/src/test/extended-query-test/tests/parse-before-bind.data +++ b/src/test/extended-query-test/tests/parse-before-bind.data @@ -40,4 +40,9 @@ 'C' 'S' "S1" 'S' 'Y' + +# DROP test table +'Q' "DROP TABLE pgproto_test1" +'Y' + 'X' diff --git a/src/test/extended-query-test/tests/query-cache-notrans.data b/src/test/extended-query-test/tests/query-cache-notrans.data index 3879b7378..1ed6c36c9 100644 --- a/src/test/extended-query-test/tests/query-cache-notrans.data +++ b/src/test/extended-query-test/tests/query-cache-notrans.data @@ -26,4 +26,9 @@ 'S' 'Y' + +# DROP test table +'Q' "DROP TABLE pgproto_test1" +'Y' + 'X' diff --git a/src/test/extended-query-test/tests/query-cache.data b/src/test/extended-query-test/tests/query-cache.data index 7150c7205..9973f22ef 100644 --- a/src/test/extended-query-test/tests/query-cache.data +++ b/src/test/extended-query-test/tests/query-cache.data @@ -45,4 +45,9 @@ 'S' 'Y' + +# DROP test table +'Q' "DROP TABLE pgproto_test1" +'Y' + 'X' [parent: c3bd4820420c]