Thread: pgsql: Refactor Perl test code
Refactor Perl test code The original code was a bit clunky; make it more amenable for further reuse by creating a new Perl package PostgresNode, which is an object-oriented representation of a single server, with some support routines such as init, start, stop, psql. This serves as a better basis on which to build further test code, and enables writing tests that use more than one server without too much complication. This commit modifies a lot of the existing test files, mostly to remove explicit calls to system commands (pg_ctl) replacing them with method calls of a PostgresNode object. The result is quite a bit more straightforward. Also move some initialization code to BEGIN and INIT blocks instead of having it straight in as top-level code. This commit also introduces package RecursiveCopy so that we can copy whole directories without having to depend on packages that may not be present on vanilla Perl 5.8 installations. I also ran perltidy on the modified files, which changes some code sites that are not otherwise touched by this patch. I tried to avoid this, but it ended up being more trouble than it's worth. Authors: Michael Paquier, Álvaro Herrera Review: Noah Misch Branch ------ master Details ------- http://git.postgresql.org/pg/commitdiff/1caef31d9e550408d0cbc5788a422dcb69736df5 Modified Files -------------- src/bin/initdb/t/001_initdb.pl | 1 + src/bin/pg_basebackup/t/010_pg_basebackup.pl | 176 +++++---- src/bin/pg_controldata/t/001_pg_controldata.pl | 11 +- src/bin/pg_ctl/t/001_start_stop.pl | 9 +- src/bin/pg_ctl/t/002_status.pl | 13 +- src/bin/pg_rewind/RewindTest.pm | 216 ++++------- src/bin/pg_rewind/t/003_extrafiles.pl | 3 +- src/bin/pg_rewind/t/004_pg_xlog_symlink.pl | 4 +- src/bin/scripts/t/010_clusterdb.pl | 22 +- src/bin/scripts/t/011_clusterdb_all.pl | 13 +- src/bin/scripts/t/020_createdb.pl | 14 +- src/bin/scripts/t/030_createlang.pl | 19 +- src/bin/scripts/t/040_createuser.pl | 18 +- src/bin/scripts/t/050_dropdb.pl | 14 +- src/bin/scripts/t/060_droplang.pl | 11 +- src/bin/scripts/t/070_dropuser.pl | 14 +- src/bin/scripts/t/080_pg_isready.pl | 9 +- src/bin/scripts/t/090_reindexdb.pl | 23 +- src/bin/scripts/t/091_reindexdb_all.pl | 10 +- src/bin/scripts/t/100_vacuumdb.pl | 17 +- src/bin/scripts/t/101_vacuumdb_all.pl | 10 +- src/bin/scripts/t/102_vacuumdb_stages.pl | 13 +- src/test/perl/PostgresNode.pm | 470 ++++++++++++++++++++++++ src/test/perl/RecursiveCopy.pm | 42 +++ src/test/perl/TestLib.pm | 319 ++++++---------- src/test/ssl/ServerSetup.pm | 34 +- src/test/ssl/t/001_ssltests.pl | 33 +- 27 files changed, 989 insertions(+), 549 deletions(-)
Alvaro Herrera <alvherre@alvh.no-ip.org> writes: > Refactor Perl test code This has broken "make check-world" for me (on RHEL 6.7): make -C src/bin check make[1]: Entering directory `/home/postgres/pgsql/src/bin' make -C initdb check make[2]: Entering directory `/home/postgres/pgsql/src/bin/initdb' rm -rf /home/postgres/pgsql/src/bin/initdb/tmp_check/log cd . && TESTDIR='/home/postgres/pgsql/src/bin/initdb' PATH="/home/postgres/pgsql/tmp_install/home/postgres/testversion/bin:$PATH" LD_LIBRARY_PATH="/home/postgres/pgsql/tmp_install/home/postgres/testversion/lib"PGPORT='65440' PG_REGRESS='/home/postgres/pgsql/src/bin/initdb/../../../src/test/regress/pg_regress'prove -I ../../../src/test/perl/ --verboset/*.pl t/001_initdb.pl .. 1..14 ok 1 - initdb --help exit code 0 ok 2 - initdb --help goes to stdout ok 3 - initdb --help nothing to stderr ok 4 - initdb --version exit code 0 ok 5 - initdb --version goes to stdout ok 6 - initdb --version nothing to stderr ok 7 - initdb with invalid option nonzero exit code ok 8 - initdb with invalid option prints error message # Looks like you planned 14 tests but ran 8. # Looks like your test exited with 25 just after 8. Dubious, test returned 25 (wstat 6400, 0x1900) Failed 6/14 subtests Test Summary Report ------------------- t/001_initdb.pl (Wstat: 6400 Tests: 8 Failed: 0) Non-zero exit status: 25 Parse errors: Bad plan. You planned 14 tests but ran 8. Files=1, Tests=8, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.08 cusr 0.01 csys = 0.11 CPU) Result: FAIL make[2]: *** [check] Error 1 make[2]: Leaving directory `/home/postgres/pgsql/src/bin/initdb' make[1]: *** [check-initdb-recurse] Error 2 make[1]: Leaving directory `/home/postgres/pgsql/src/bin' make: *** [check-world-src/bin-recurse] Error 2 The buildfarm looks pretty unhappy too, though I've not checked to see if it's exactly the same symptom everywhere. regards, tom lane
On Thu, Dec 3, 2015 at 8:38 AM, Tom Lane wrote: > Test Summary Report > ------------------- > t/001_initdb.pl (Wstat: 6400 Tests: 8 Failed: 0) > Non-zero exit status: 25 > Parse errors: Bad plan. You planned 14 tests but ran 8. > Files=1, Tests=8, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.08 cusr 0.01 csys = 0.11 CPU) > Result: FAIL > make[2]: *** [check] Error 1 > make[2]: Leaving directory `/home/postgres/pgsql/src/bin/initdb' > make[1]: *** [check-initdb-recurse] Error 2 > make[1]: Leaving directory `/home/postgres/pgsql/src/bin' > make: *** [check-world-src/bin-recurse] Error 2 > > The buildfarm looks pretty unhappy too, though I've not checked to see if > it's exactly the same symptom everywhere. Or in more details: Undefined subroutine &TestLib::run called at /Users/mpaquier/git/postgres/src/bin/initdb/../../../src/test/perl/TestLib.pm line 146. I am seeing the same failure on all the machines in the buildfarm. The issue is fixed by the patch attached. This has been visibly forgotten in the version pushed. Regards, -- Michael
Attachment
Michael Paquier wrote: > Or in more details: > Undefined subroutine &TestLib::run called at > /Users/mpaquier/git/postgres/src/bin/initdb/../../../src/test/perl/TestLib.pm > line 146. > I am seeing the same failure on all the machines in the buildfarm. > > The issue is fixed by the patch attached. This has been visibly > forgotten in the version pushed. Yeah. Pushed. -- Álvaro Herrera http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Alvaro Herrera <alvherre@2ndquadrant.com> writes: > Michael Paquier wrote: >> The issue is fixed by the patch attached. This has been visibly >> forgotten in the version pushed. > Yeah. Pushed. "make check-world" passes again here. Thanks. regards, tom lane