[Rt-commit] r15387 - in rt/3.8/trunk: .

ruz at bestpractical.com ruz at bestpractical.com
Fri Aug 22 20:20:39 EDT 2008


Author: ruz
Date: Fri Aug 22 20:20:29 2008
New Revision: 15387

Modified:
   rt/3.8/trunk/   (props changed)
   rt/3.8/trunk/lib/RT/Handle.pm
   rt/3.8/trunk/lib/RT/Test.pm

Log:
 r15285 at cubic-pc (orig r15233):  falcone | 2008-08-18 22:06:11 +0400
 * initial code to get Pg to actually drop databases when 
   we're done with the test and to get it to create
   databases correctly so it doesn't block when two
   creates run at the same time.
 
 failed in t/mail the last time it was run (thus why it isn't
 in trunk yet)


Modified: rt/3.8/trunk/lib/RT/Handle.pm
==============================================================================
--- rt/3.8/trunk/lib/RT/Handle.pm	(original)
+++ rt/3.8/trunk/lib/RT/Handle.pm	Fri Aug 22 20:20:29 2008
@@ -319,8 +319,8 @@
     elsif ( $db_type eq 'Pg' ) {
         # XXX: as we get external DBH we don't know if RaiseError or PrintError
         # are enabled, so we have to setup it here and restore them back
-        $status = $dbh->do("CREATE DATABASE $db_name WITH ENCODING='UNICODE'")
-            || $dbh->do("CREATE DATABASE $db_name");
+        $status = $dbh->do("CREATE DATABASE $db_name WITH ENCODING='UNICODE' TEMPLATE template0")
+            || $dbh->do("CREATE DATABASE $db_name TEMPLATE template0");
     }
     elsif ( $db_type eq 'Informix' ) {
         local $ENV{'DB_LOCALE'} = 'en_us.utf8';

Modified: rt/3.8/trunk/lib/RT/Test.pm
==============================================================================
--- rt/3.8/trunk/lib/RT/Test.pm	(original)
+++ rt/3.8/trunk/lib/RT/Test.pm	Fri Aug 22 20:20:29 2008
@@ -51,7 +51,7 @@
 use strict;
 use warnings;
 
-use Test::More;
+use base 'Test::More';
 use Socket;
 use File::Temp;
 use File::Spec;
@@ -239,7 +239,7 @@
 sub started_ok {
     require RT::Test::Web;
     if ( $existing_server ) {
-        ok(1, "using existing server $existing_server");
+        Test::More::ok(1, "using existing server $existing_server");
         RT::Logger->warning( $existing_server);
         return ($existing_server, RT::Test::Web->new);
     }
@@ -270,7 +270,7 @@
     my $baseurl = shift;
     my $queue   = shift || 'general';
     my $action  = shift || 'correspond';
-    ok(open(my $mail, "|$RT::BinPath/rt-mailgate --url $baseurl --queue $queue --action $action"), "Opened the mailgate - $!");
+    Test::More::ok(open(my $mail, "|$RT::BinPath/rt-mailgate --url $baseurl --queue $queue --action $action"), "Opened the mailgate - $!");
     return $mail;
 }
 
@@ -279,13 +279,13 @@
     my $class = shift;
     my $mail  = shift;
     close $mail;
-    is ($? >> 8, 0, "The mail gateway exited normally. yay");
+    Test::More::is ($? >> 8, 0, "The mail gateway exited normally. yay");
 }
 
 sub mailsent_ok {
     my $class = shift;
     my $expected  = shift;
-    is ($mailsent, $expected, "The number of mail sent ($expected) matches. yay");
+    Test::More::is ($mailsent, $expected, "The number of mail sent ($expected) matches. yay");
 }
 
 =head1 UTILITIES
@@ -434,7 +434,7 @@
         my $ace = RT::ACE->new( $RT::SystemUser );
         my ($status, $msg) = $ace->RT::Record::Create( %$entry );
         unless ( $status ) {
-            diag "couldn't create a record: $msg";
+            Test::More::diag "couldn't create a record: $msg";
         }
     }
 }
@@ -537,10 +537,10 @@
     unless ( $status >> 8 ) {
         ($id) = ($gate_result =~ /Ticket:\s*(\d+)/i);
         unless ( $id ) {
-            diag "Couldn't find ticket id in text:\n$gate_result" if $ENV{'TEST_VERBOSE'};
+            Test::More::diag "Couldn't find ticket id in text:\n$gate_result" if $ENV{'TEST_VERBOSE'};
         }
     } else {
-        diag "Mailgate output:\n$gate_result" if $ENV{'TEST_VERBOSE'};
+        Test::More::diag "Mailgate output:\n$gate_result" if $ENV{'TEST_VERBOSE'};
     }
     return ($status, $id);
 }
@@ -578,7 +578,7 @@
 
     $path = File::Spec->catfile( @$path ) if ref $path eq 'ARRAY';
 
-    diag "reading content of '$path'" if $ENV{'TEST_VERBOSE'};
+    Test::More::diag "reading content of '$path'" if $ENV{'TEST_VERBOSE'};
 
     open my $fh, "<:raw", $path
         or do { warn "couldn't open file '$path': $!" unless $args{noexist}; return '' };
@@ -789,9 +789,15 @@
 }
 
 END {
+    my $Test = RT::Test->builder;
+    return if $Test->{Original_Pid} != $$;
     if ( $ENV{RT_TEST_PARALLEL} && $created_new_db ) {
-        my $dbh =
-          _get_dbh( RT::Handle->DSN, $ENV{RT_DBA_USER}, $ENV{RT_DBA_PASSWORD} );
+
+        # Pg doesn't like if you issue a DROP DATABASE while still connected
+        my $dbh = $RT::Handle->dbh;
+        $dbh->disconnect if $dbh;
+
+        $dbh = _get_dbh( RT::Handle->SystemDSN, $ENV{RT_DBA_USER}, $ENV{RT_DBA_PASSWORD} );
         RT::Handle->DropDatabase( $dbh, Force => 1 );
         $dbh->disconnect;
     }


More information about the Rt-commit mailing list