Author: turnstep
Date: Thu Jan 17 14:37:39 2008
New Revision: 10593

Modified:
   DBD-Pg/trunk/README
   DBD-Pg/trunk/SIGNATURE
   DBD-Pg/trunk/t/01connect.t
   DBD-Pg/trunk/t/dbdpg_test_setup.pl

Log:
Try really hard to find a database connection when testing.
Drop everything at the end of each test, and do a 
CASCADE for the final schema drop. Show the connection 
error in the 01connect.t output, as well as any stuff that 
we automagically populated to get a connection.
Update SIGNATURE in prep for RC2.


Modified: DBD-Pg/trunk/README
==============================================================================
--- DBD-Pg/trunk/README (original)
+++ DBD-Pg/trunk/README Thu Jan 17 14:37:39 2008
@@ -133,6 +133,9 @@
 When reporting test failures, please use TEST_VERBOSE=1, do *not* 
 set DBD_TRACE unless requested, and send only the relevant sections.
 
+If the first connection fails and DBI_DSN is not set, the tests may 
+attempt to connect as the user 'postgres' to the database 'postgres'. 
+See the t/dbdpg_test_setup.pl for the exact process.
 
 TROUBLESHOOTING:
 ----------------

Modified: DBD-Pg/trunk/SIGNATURE
==============================================================================
--- DBD-Pg/trunk/SIGNATURE      (original)
+++ DBD-Pg/trunk/SIGNATURE      Thu Jan 17 14:37:39 2008
@@ -21,35 +21,35 @@
 SHA1 c96ee340daf50be32719f24ccfdaa486bea703d7 META.yml
 SHA1 2334400a1b429c66d968d0293eb030a4e1b5d724 Makefile.PL
 SHA1 f2991c4669223cae5cb13ecb4b5fff2d20a064d0 Pg.h
-SHA1 9fc5cdc5a836ce9da0ae44eca9dde83de53cbd81 Pg.pm
+SHA1 fc45f8b3a9eb0f6c8c7f49bd41db4552f0c2b5d2 Pg.pm
 SHA1 07f9840ff41ad1368060a7a3f1ccfb487cb8b55f Pg.xs
-SHA1 5b35583cd40437f2466ed80d32df623ae1ba2253 README
+SHA1 df0e940d894147dd12530c199920e6a41e1a1e23 README
 SHA1 261d85906f33505b32c431e87b98e1cd9293807c README.dev
 SHA1 968d5fad61bce160b31a9cb1a21dd240b9df930f README.win32
 SHA1 cdeb69c8488d0a87430f2c24a07358213c6de02b TODO
-SHA1 3016a84170d36eb13e7bf6ea144a46672d197384 dbdimp.c
+SHA1 c626825ca88b498f53a7f702503ff69b1a0579b8 dbdimp.c
 SHA1 656eaaa05a5f50f7282d838f44b09cb585a11e60 dbdimp.h
 SHA1 aeb8bcf6c0b2314230ecd4dc3e3e275d972ae195 quote.c
 SHA1 86aa3685c343d4f1a014ccd1ca5cd7d87de48e9b quote.h
 SHA1 b0bb74d7bff1d376f9bfff7e3d7505696b284fe0 t/00-signature.t
 SHA1 3bc6be6dc22d6ed0f1b51108b7786e70bfa99131 t/00basic.t
-SHA1 2319351229d79e396c81f34a9f07f625ef7d2bbf t/01connect.t
+SHA1 ea02effa11d914c101e5bd546407b6d3ce72bf18 t/01connect.t
 SHA1 878c7eb0941f7b19f4a9a61d0d2d9a3321905a96 t/01constants.t
-SHA1 f6e01e03d989f0233e0190090412c806ba867f49 t/02attribs.t
-SHA1 4b665ed53818ad25e21fdb85c51367298509bad2 t/03dbmethod.t
+SHA1 066cbab43381421009f4dcd4d521663df1eebb67 t/02attribs.t
+SHA1 c9e3d05761caaf620ad7ecec6d4534e059609252 t/03dbmethod.t
 SHA1 cd993fb4285df4113967dedf5f1b2b5fc2d7ed12 t/03smethod.t
 SHA1 ea369ae9b1abb8ba607fa7a2b3c7d9cb7d41449a t/04misc.t
 SHA1 477ee3896ecd763324da5514380cb91f66ad86d5 t/06bytea.t
-SHA1 8fcec6047e63998c09c77e25aacc55ece10970d6 t/07copy.t
+SHA1 14867de37becfd9a1ccf5bc1a2d0683f62878d71 t/07copy.t
 SHA1 a4a21838c94d8799152c0b53ea244fd0d3f99b5b t/08async.t
 SHA1 68200d8282023da6f6a898ca272deb85d11391b4 t/09arrays.t
 SHA1 377a603cbbb9aa6c3c816e4292396a31a87e3080 t/12placeholders.t
 SHA1 94541bc74e399793f9045dabf02c05bd186267f7 t/20savepoints.t
-SHA1 c0666c324826fb1377f7b21c81e23e4e5273fafd t/99_perlcritic.t
+SHA1 cdd9acbb47069980bf45daa8ae962dedc9a1a3af t/99_perlcritic.t
 SHA1 87a15c775cdf958f35ecd8df37b8ba1e7891acc0 t/99_pod.t
 SHA1 e9e984b3c3366d5cee873f1dc59e2b7c26e744ee t/99_yaml.t
 SHA1 0cbb33eb5cd1971b0bf9a4df834f41f1d9ec9df3 t/99cleanup.t
-SHA1 2c07b489013acce354164930c16398270b4837bf t/dbdpg_test_setup.pl
+SHA1 c82c9c02415eb935f3245c483c431da436433a02 t/dbdpg_test_setup.pl
 SHA1 bc4a58bdd5e853139f9e1fc6129f83e50a07a2c6 t/lib/App/Info.pm
 SHA1 58befda00c12b1721875262505112203bf230450 t/lib/App/Info/Handler.pm
 SHA1 b5bf85b12a5fc207c44113a9c028fb7fbd68531f t/lib/App/Info/Handler/Prompt.pm
@@ -62,7 +62,7 @@
 SHA1 f07cd5ecaeb854c81ceb9206364979cf607e6546 win32.mak
 -----BEGIN PGP SIGNATURE-----
 
-iD8DBQFHjuMCvJuQZxSWSsgRA6d4AKCjBYk72vEn6KT0rkAPBjEgmZL7CQCgxQfM
-fYUF6uFpVAyV/JsH0fgPfGs=
-=QDVG
+iD8DBQFHj9gyvJuQZxSWSsgRA0RpAJ4qTUkqOrJ8tmk2awCeozbPSzy3IwCfYd9v
+MNHRQoj1Wk8nH/ewKNXEhVk=
+=2oJ1
 -----END PGP SIGNATURE-----

Modified: DBD-Pg/trunk/t/01connect.t
==============================================================================
--- DBD-Pg/trunk/t/01connect.t  (original)
+++ DBD-Pg/trunk/t/01connect.t  Thu Jan 17 14:37:39 2008
@@ -15,7 +15,9 @@
 ## Define this here in case we get to the END block before a connection is 
made.
 my ($pgversion,$pglibversion,$pgvstring,$pgdefport) = ('?','?','?','?');
 
-my $dbh = connect_database();
+my ($dbh,$connerror,$helpconnect);
+
+($helpconnect,$connerror,$dbh) = connect_database();
 
 if (! defined $dbh) {
        plan skip_all => 'Connection to database failed, cannot continue 
testing';
@@ -121,12 +123,28 @@
                        $extra .= sprintf "\n%-21s $ENV{$name}", $name;
                }
        }
-       for my $name (qw/DBI_DRIVER DBI_USER DBI_PASS DBI_AUTOPROXY/) {
+       for my $name (qw/DBI_DRIVER DBI_AUTOPROXY/) {
                if (exists $ENV{$name} and defined $ENV{$name}) {
                        $extra .= sprintf "\n%-21s $ENV{$name}", $name;
                }
        }
 
+       if ($helpconnect) {
+               $extra .= "\nAdjusted:             ";
+               if ($helpconnect & 1) {
+                       $extra .= 'DBI_DSN ';
+               }
+               if ($helpconnect & 4) {
+                       $extra .= 'DBI_USER';
+               }
+       }
+
+       if (defined $connerror) {
+               $connerror =~ s/.+?failed: //;
+               $connerror =~ s{\n at t/dbdpg.*}{}m;
+               $extra .= "\nError was: $connerror";
+       }
+
        diag
                "\nDBI                   Version $DBI::VERSION\n".
                "DBD::Pg               Version $ver\n".

Modified: DBD-Pg/trunk/t/dbdpg_test_setup.pl
==============================================================================
--- DBD-Pg/trunk/t/dbdpg_test_setup.pl  (original)
+++ DBD-Pg/trunk/t/dbdpg_test_setup.pl  Thu Jan 17 14:37:39 2008
@@ -3,6 +3,7 @@
 
 use strict;
 use warnings;
+use Data::Dumper;
 use DBI;
 select(($|=1,select(STDERR),$|=1)[1]);
 
@@ -37,7 +38,10 @@
 
        ## Connect to the database (unless 'dbh' is passed in)
        ## Setup all the tables (unless 'nosetup' is passed in)
-       ## Returns the database handle (unless 'disconnect' is passed in)
+       ## Returns three values:
+       ## 1. helpconnect for use by 01connect.t
+       ## 2. Any error generated
+       ## 3. The database handle, or undef
        ## The returned handle has AutoCommit=0 (unless AutoCommit is passed in)
 
        my $arg = shift || {};
@@ -45,7 +49,9 @@
 
        my $dbh = $arg->{dbh} || '';
 
+       my $helpconnect = 0;
        if (!defined $ENV{DBI_DSN}) {
+               $helpconnect = 1;
                $ENV{DBI_DSN} = 'dbi:Pg:';
        }
 
@@ -54,9 +60,24 @@
                        $dbh = DBI->connect($ENV{DBI_DSN}, $ENV{DBI_USER}, 
$ENV{DBI_PASS},
                                                                {RaiseError => 
1, PrintError => 0, AutoCommit => 1});
                };
-               $@ and return undef;
+               if ($@) {
+                       return $helpconnect, $@, undef if $@ !~ /FATAL/ or 
defined $ENV{DBI_USER};
+                       ## Try one more time as postgres user (and possibly 
database)
+                       if ($helpconnect) {
+                               $ENV{DBI_DSN} .= 'dbname=postgres';
+                               $helpconnect += 2;
+                       }
+                       $helpconnect += 4;
+                       $ENV{DBI_USER} = 'postgres';
+                       eval {
+                               $dbh = DBI->connect($ENV{DBI_DSN}, 
$ENV{DBI_USER}, $ENV{DBI_PASS},
+                                                                       
{RaiseError => 1, PrintError => 0, AutoCommit => 1});
+                       };
+                       return $helpconnect, $@, undef if $@;
+               }
        }
        if ($arg->{nosetup}) {
+               return $helpconnect, undef, $dbh unless schema_exists($dbh, $S);
                $dbh->do("SET search_path TO $S");
        }
        else {
@@ -78,26 +99,26 @@
   testarray  text[][],
   testarray2 int[],
   "CaseTest" boolean,
-  bytetest   bytea 
+  bytetest   bytea
 )
 };
 
-$dbh->{Warn} = 0;
-$dbh->do($SQL);
-$dbh->{Warn} = 1;
-$dbh->do(q{COMMENT ON COLUMN dbd_pg_test.id IS 'Bob is your uncle'});
+               $dbh->{Warn} = 0;
+               $dbh->do($SQL);
+               $dbh->{Warn} = 1;
+               $dbh->do(q{COMMENT ON COLUMN dbd_pg_test.id IS 'Bob is your 
uncle'});
 
 } ## end setup
 
 $dbh->commit() unless $dbh->{AutoCommit};
 
 if ($arg->{disconnect}) {
-$dbh->disconnect();
-return;
+       $dbh->disconnect();
+       return $helpconnect, undef, undef;
 }
 
 $dbh->{AutoCommit} = 0 unless $arg->{AutoCommit};
-return $dbh;
+return $helpconnect, undef, $dbh;
 
 } ## end of connect_database
 
@@ -132,8 +153,7 @@
        my $dbh = shift;
        my $type = shift || 0;
 
-       ## For now, don't drop between individual tests
-       return if $type eq 'test';
+       ## For now, we always run and disregard the type
 
        $dbh->rollback() if ! $dbh->{AutoCommit};
 
@@ -151,7 +171,7 @@
 
        for my $schema (@schemas) {
                next if ! schema_exists($dbh,$schema);
-               $dbh->do("DROP SCHEMA $schema");
+               $dbh->do("DROP SCHEMA $schema CASCADE");
        }
        $dbh->commit() if ! $dbh->{AutoCommit};
 

Reply via email to