[Rt-commit] rt branch, 4.0/changes-for-rtir-3.0, updated. rt-3.9.7-1201-g968862a

Ruslan Zakirov ruz at bestpractical.com
Wed Feb 9 18:01:04 EST 2011


The branch, 4.0/changes-for-rtir-3.0 has been updated
       via  968862a7c9e07b9a9cf1827ac47b497b4c624b96 (commit)
       via  805def476a641864386a7c308c5d98e6dd6a5260 (commit)
       via  50d4ec801495e9a37ee0ebf60983a1fc348255a9 (commit)
      from  8e804894ae3cd183209f9cc17d246e33104ff060 (commit)

Summary of changes:
 lib/RT/Test.pm |   67 ++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 43 insertions(+), 24 deletions(-)

- Log -----------------------------------------------------------------
commit 50d4ec801495e9a37ee0ebf60983a1fc348255a9
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Feb 10 01:43:10 2011 +0300

    extract create and drop database private helpers

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index db47451..d28fecd 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -376,19 +376,7 @@ sub bootstrap_db {
     }
 
     unless ($args{nodb}) {
-        # bootstrap with dba cred
-        my $dbh = _get_dbh(
-            RT::Handle->SystemDSN,
-            $ENV{RT_DBA_USER}, $ENV{RT_DBA_PASSWORD}
-        );
-
-        unless ( $ENV{RT_TEST_PARALLEL} ) {
-            # already dropped db in parallel tests, need to do so for other cases.
-            RT::Handle->DropDatabase( $dbh, Force => 1 )
-        }
-        RT::Handle->CreateDatabase( $dbh );
-        $dbh->disconnect;
-        $created_new_db++;
+        __create_database();
 
         __reconnect_rt('dba');
         $RT::Handle->InsertSchema;
@@ -513,6 +501,39 @@ sub _get_dbh {
     return $dbh;
 }
 
+sub __create_database {
+    # bootstrap with dba cred
+    my $dbh = _get_dbh(
+        RT::Handle->SystemDSN,
+        $ENV{RT_DBA_USER}, $ENV{RT_DBA_PASSWORD}
+    );
+
+    unless ( $ENV{RT_TEST_PARALLEL} ) {
+        # already dropped db in parallel tests, need to do so for other cases.
+        __drop_database( $dbh );
+
+    }
+    RT::Handle->CreateDatabase( $dbh );
+    $dbh->disconnect;
+    $created_new_db++;
+}
+
+sub __drop_database {
+    my $dbh = shift;
+
+    # Pg doesn't like if you issue a DROP DATABASE while still connected
+    # it's still may fail if web-server is out there and holding a connection
+    __disconnect_rt();
+
+    my $my_dbh = $dbh? 0 : 1;
+    $dbh ||= _get_dbh(
+        RT::Handle->SystemDSN,
+        $ENV{RT_DBA_USER}, $ENV{RT_DBA_PASSWORD}
+    );
+    RT::Handle->DropDatabase( $dbh, Force => 1 );
+    $dbh->disconnect if $my_dbh;
+}
+
 sub __reconnect_rt {
     my $as_dba = shift;
     __disconnect_rt();
@@ -1405,13 +1426,7 @@ END {
     }
 
     if ( $ENV{RT_TEST_PARALLEL} && $created_new_db ) {
-
-        # Pg doesn't like if you issue a DROP DATABASE while still connected
-        __disconnect_rt();
-
-        my $dbh = _get_dbh( RT::Handle->SystemDSN, $ENV{RT_DBA_USER}, $ENV{RT_DBA_PASSWORD} );
-        RT::Handle->DropDatabase( $dbh, Force => 1 );
-        $dbh->disconnect;
+        __drop_database();
     }
 }
 

commit 805def476a641864386a7c308c5d98e6dd6a5260
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Feb 10 01:44:29 2011 +0300

    disconnect and clean every possible handle for sure

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index d28fecd..380e681 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -555,8 +555,11 @@ sub __disconnect_rt {
     # look at %DBIHandle and $PrevHandle in DBIx::SB::Handle for explanation
     return unless $RT::Handle;
     my $dbh = $RT::Handle->dbh;
-    $RT::Handle->dbh(undef);
     $dbh->disconnect if $dbh;
+
+    %DBIx::SearchBuilder::Handle::DBIHandle = ();
+    $DBIx::SearchBuilder::Handle::PrevHandle = undef;
+
     $RT::Handle = undef;
 }
 

commit 968862a7c9e07b9a9cf1827ac47b497b4c624b96
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Feb 10 01:47:04 2011 +0300

    minor, use less reconnections

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 380e681..8c82cf2 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -378,7 +378,7 @@ sub bootstrap_db {
     unless ($args{nodb}) {
         __create_database();
 
-        __reconnect_rt('dba');
+        __reconnect_rt('as dba');
         $RT::Handle->InsertSchema;
 
         my $db_type = RT->Config->Get('DatabaseType');
@@ -398,6 +398,7 @@ sub bootstrap_db {
             $RT::Handle->InsertData( $RT::EtcPath . "/initialdata" );
             DBIx::SearchBuilder::Record::Cachable->FlushCache;
         }
+
         $self->bootstrap_plugins_db( %args );
         __reconnect_rt();
     }
@@ -459,15 +460,14 @@ sub bootstrap_plugins_db {
             next;
         }
 
+        __reconnect_rt('as dba');
 
         { # schema
-            __reconnect_rt('dba');
             my ($ret, $msg) = $RT::Handle->InsertSchema( undef, $etc_path );
             Test::More::ok($ret || $msg =~ /^Couldn't find schema/, "Created schema: ".($msg||''));
         }
 
         { # ACLs
-            __reconnect_rt('dba');
             my ($ret, $msg) = $RT::Handle->InsertACL( undef, $etc_path );
             Test::More::ok($ret || $msg =~ /^Couldn't find ACLs/, "Created ACL: ".($msg||''));
         }
@@ -554,6 +554,7 @@ sub __reconnect_rt {
 sub __disconnect_rt {
     # look at %DBIHandle and $PrevHandle in DBIx::SB::Handle for explanation
     return unless $RT::Handle;
+
     my $dbh = $RT::Handle->dbh;
     $dbh->disconnect if $dbh;
 

-----------------------------------------------------------------------


More information about the Rt-commit mailing list