[Rt-commit] rt branch, 4.0/changes-for-rtir-3.0, created. rt-3.9.7-1198-g8e80489

Ruslan Zakirov ruz at bestpractical.com
Tue Jan 18 06:37:38 EST 2011


The branch, 4.0/changes-for-rtir-3.0 has been created
        at  8e804894ae3cd183209f9cc17d246e33104ff060 (commit)

- Log -----------------------------------------------------------------
commit fe4ada817fd8c63777db739185d60c5465ec0648
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Jan 13 02:55:22 2011 +0300

    bootstrap DB if we're testing a plugin that doesn't require any plugins

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index d0d465e..3cbe896 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -417,19 +417,21 @@ sub bootstrap_plugins {
     my $self = shift;
     my %args = @_;
 
-    return unless $args{'requires'};
-
-    my @plugins = @{ $args{'requires'} };
+    my @plugins;
+    push @plugins, @{ $args{'requires'} }
+        if $args{'requires'};
     push @plugins, $args{'testing'}
         if $args{'testing'};
 
-    require RT::Plugin;
+    return unless @plugins;
+
     my $cwd;
     if ( $args{'testing'} ) {
         require Cwd;
         $cwd = Cwd::getcwd();
     }
 
+    require RT::Plugin;
     my $old_func = \&RT::Plugin::_BasePath;
     no warnings 'redefine';
     *RT::Plugin::_BasePath = sub {

commit dbcf57e63805fbd1a5c3d26eecc00f791cf2e7a6
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Jan 18 10:14:06 2011 +0300

    make it possible to override user/pass in ::Handle->Connect

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 49b5140..6f1118f 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -103,6 +103,7 @@ Takes nothing.
 
 sub Connect {
     my $self = shift;
+    my %args = (@_);
 
     my $db_type = RT->Config->Get('DatabaseType');
     if ( $db_type eq 'Oracle' ) {
@@ -113,6 +114,7 @@ sub Connect {
     $self->SUPER::Connect(
         User => RT->Config->Get('DatabaseUser'),
         Password => RT->Config->Get('DatabasePassword'),
+        %args,
     );
 
     if ( $db_type eq 'mysql' ) {

commit 17c23318048decd2f541878838dc6f27b10b9765
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Jan 18 10:17:02 2011 +0300

    don't connect using system DSN when we don't need it

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 3cbe896..afea760 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -353,10 +353,6 @@ sub bootstrap_db {
     }
 
     require RT::Handle;
-    # bootstrap with dba cred
-    my $dbh = _get_dbh(RT::Handle->SystemDSN,
-               $ENV{RT_DBA_USER}, $ENV{RT_DBA_PASSWORD});
-
     if (my $forceopt = $ENV{RT_TEST_FORCE_OPT}) {
         Test::More::diag "forcing $forceopt";
         $args{$forceopt}=1;
@@ -371,6 +367,12 @@ 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 )

commit 8da37c41a6ae127adc457a488b21f8346d199b0c
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Jan 18 10:18:03 2011 +0300

    __reconnect_rt and __disconnect_rt functions

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index afea760..ff5ef35 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -512,6 +512,33 @@ sub _get_dbh {
     return $dbh;
 }
 
+sub __reconnect_rt {
+    my $as_dba = shift;
+    __disconnect_rt();
+
+    # look at %DBIHandle and $PrevHandle in DBIx::SB::Handle for explanation
+    $RT::Handle = RT::Handle->new;
+    $RT::Handle->dbh( undef );
+    $RT::Handle->Connect(
+        $as_dba
+        ? (User => $ENV{RT_DBA_USER}, Password => $ENV{RT_DBA_PASSWORD})
+        : ()
+    );
+    $RT::Handle->PrintError;
+    $RT::Handle->dbh->{PrintError} = 1;
+    return $RT::Handle->dbh;
+}
+
+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;
+    $RT::Handle = undef;
+}
+
+
 =head1 UTILITIES
 
 =head2 load_or_create_user

commit 5487da39b1429f2ad0590b677208055b075da1c4
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Jan 18 10:20:20 2011 +0300

    use reconnect and diconnect functions

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index ff5ef35..8cd3006 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -143,7 +143,7 @@ sub import {
 
     RT::InitPluginPaths();
 
-    RT::ConnectToDatabase()
+    __reconnect_rt()
         unless $args{nodb};
 
     RT::InitClasses();
@@ -381,34 +381,23 @@ sub bootstrap_db {
         $dbh->disconnect;
         $created_new_db++;
 
-        $dbh = _get_dbh(RT::Handle->DSN,
-                        $ENV{RT_DBA_USER}, $ENV{RT_DBA_PASSWORD});
-
-        $RT::Handle = RT::Handle->new;
-        $RT::Handle->dbh( $dbh );
-        $RT::Handle->InsertSchema( $dbh );
+        __reconnect_rt('dba');
+        $RT::Handle->InsertSchema;
 
         my $db_type = RT->Config->Get('DatabaseType');
-        $RT::Handle->InsertACL( $dbh ) unless $db_type eq 'Oracle';
+        $RT::Handle->InsertACL unless $db_type eq 'Oracle';
 
-        $RT::Handle = RT::Handle->new;
-        $RT::Handle->dbh( undef );
-        RT->ConnectToDatabase;
         RT->InitLogging;
 
         unless ($args{noinitialdata}) {
+            __reconnect_rt();
             $RT::Handle->InsertInitialData;
 
             DBIx::SearchBuilder::Record::Cachable->FlushCache;
         }
 
-        $RT::Handle = RT::Handle->new;
-        $RT::Handle->dbh( undef );
-        RT->ConnectToDatabase();
-        $RT::Handle->PrintError;
-        $RT::Handle->dbh->{PrintError} = 1;
-
         unless ( $args{'nodata'} ) {
+            __reconnect_rt();
             $RT::Handle->InsertData( $RT::EtcPath . "/initialdata" );
             DBIx::SearchBuilder::Record::Cachable->FlushCache;
         }
@@ -1254,12 +1243,10 @@ sub start_plack_server {
         my $Tester = Test::Builder->new;
         $Tester->ok(1, @_);
 
-        $RT::Handle = RT::Handle->new;
-        $RT::Handle->dbh( undef );
-        RT->ConnectToDatabase;
         # the attribute cache holds on to a stale dbh
         delete $RT::System->{attributes};
 
+        __reconnect_rt();
         return ("http://localhost:$port", RT::Test::Web->new);
     }
 
@@ -1407,10 +1394,9 @@ END {
     if ( $ENV{RT_TEST_PARALLEL} && $created_new_db ) {
 
         # Pg doesn't like if you issue a DROP DATABASE while still connected
-        my $dbh = $RT::Handle->dbh;
-        $dbh->disconnect if $dbh;
+        __disconnect_rt();
 
-        $dbh = _get_dbh( RT::Handle->SystemDSN, $ENV{RT_DBA_USER}, $ENV{RT_DBA_PASSWORD} );
+        my $dbh = _get_dbh( RT::Handle->SystemDSN, $ENV{RT_DBA_USER}, $ENV{RT_DBA_PASSWORD} );
         RT::Handle->DropDatabase( $dbh, Force => 1 );
         $dbh->disconnect;
     }

commit 2062e17b3ce4715f0b4cef42c16bfa931941893e
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Jan 18 10:31:30 2011 +0300

    create plugins element in %args out of testing and requires

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 8cd3006..db7474a 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -130,6 +130,11 @@ sub import {
         $class->builder->no_plan unless $class->builder->has_plan;
     }
 
+    push @{ $args{'plugins'} ||= [] }, @{ $args{'requires'} }
+        if $args{'requires'};
+    push @{ $args{'plugins'} ||= [] }, $args{'testing'}
+        if $args{'testing'};
+
     $class->bootstrap_tempdir;
 
     $class->bootstrap_config( %args );

commit 4b6e1720f3b312bf5f87a1e48057d572702f4fc7
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Jan 18 10:32:20 2011 +0300

    put plugins into @Plugins when bootstraping config

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index db7474a..098d03b 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -246,6 +246,10 @@ Set( \$RTAddressRegexp , qr/^bad_re_that_doesnt_match\$/);
         print $config "Set( \$DatabaseUser , 'u${dbname}');\n";
     }
 
+    if ( $args{'plugins'} ) {
+        print $config "Set( \@Plugins, qw(". join( ' ', @{ $args{'plugins'} } ) .") );\n";
+    }
+
     if ( $INC{'Devel/Cover.pm'} ) {
         print $config "Set( \$DevelMode, 0 );\n";
     }

commit 40b52d891114e640936853c290ad1e086b13a4db
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Jan 18 10:34:29 2011 +0300

    split bootstrap_plugins into *_paths and *_db functions

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 098d03b..aac1c62 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -413,17 +413,12 @@ sub bootstrap_db {
     }
 }
 
-sub bootstrap_plugins {
+sub bootstrap_plugins_paths {
     my $self = shift;
     my %args = @_;
 
-    my @plugins;
-    push @plugins, @{ $args{'requires'} }
-        if $args{'requires'};
-    push @plugins, $args{'testing'}
-        if $args{'testing'};
-
-    return unless @plugins;
+    return unless $args{'plugins'};
+    my @plugins = @{ $args{'plugins'} };
 
     my $cwd;
     if ( $args{'testing'} ) {
@@ -446,9 +441,11 @@ sub bootstrap_plugins {
         }
         return $old_func->(@_);
     };
+}
 
-    RT->Config->Set( Plugins => @plugins );
-    RT->InitPluginPaths();
+sub bootstrap_plugins_db {
+    my $self = shift;
+    my %args = @_;
 
     my $dba_dbh;
     $dba_dbh = _get_dbh(

commit d54d43bef1dcfe81eef646fe7b8a9511527b7e94
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Jan 18 10:35:47 2011 +0300

    refactor bootstrap plugin_db

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index aac1c62..551d9c2 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -447,13 +447,11 @@ sub bootstrap_plugins_db {
     my $self = shift;
     my %args = @_;
 
-    my $dba_dbh;
-    $dba_dbh = _get_dbh(
-        RT::Handle->DSN,
-        $ENV{RT_DBA_USER}, $ENV{RT_DBA_PASSWORD},
-    ) if @plugins;
+    return unless $args{'plugins'};
 
     require File::Spec;
+
+    my @plugins = @{ $args{'plugins'} };
     foreach my $name ( @plugins ) {
         my $plugin = RT::Plugin->new( name => $name );
         Test::More::diag( "Initializing DB for the $name plugin" )
@@ -463,31 +461,37 @@ sub bootstrap_plugins_db {
         Test::More::diag( "etc path of the plugin is '$etc_path'" )
             if $ENV{'TEST_VERBOSE'};
 
-        if ( -e $etc_path ) {
-            my ($ret, $msg) = $RT::Handle->InsertSchema( $dba_dbh, $etc_path );
-            Test::More::ok($ret || $msg =~ /^Couldn't find schema/, "Created schema: ".($msg||''));
-
-            ($ret, $msg) = $RT::Handle->InsertACL( $dba_dbh, $etc_path );
-            Test::More::ok($ret || $msg =~ /^Couldn't find ACLs/, "Created ACL: ".($msg||''));
-
-            my $data_file = File::Spec->catfile( $etc_path, 'initialdata' );
-            if ( -e $data_file ) {
-                ($ret, $msg) = $RT::Handle->InsertData( $data_file );;
-                Test::More::ok($ret, "Inserted data".($msg||''));
-            } else {
-                Test::More::ok(1, "There is no data file" );
-            }
-        }
-        else {
+        unless ( -e $etc_path ) {
 # we can not say if plugin has no data or we screwed with etc path
             Test::More::ok(1, "There is no etc dir: no schema" );
             Test::More::ok(1, "There is no etc dir: no ACLs" );
             Test::More::ok(1, "There is no etc dir: no data" );
+            next;
+        }
+
+
+        { # 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||''));
         }
 
-        $RT::Handle->Connect; # XXX: strange but mysql can loose connection
+        { # 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||''));
+        }
+
+        # data
+        my $data_file = File::Spec->catfile( $etc_path, 'initialdata' );
+        if ( -e $data_file ) {
+            __reconnect_rt();
+            my ($ret, $msg) = $RT::Handle->InsertData( $data_file );;
+            Test::More::ok($ret, "Inserted data".($msg||''));
+        } else {
+            Test::More::ok(1, "There is no data file" );
+        }
     }
-    $dba_dbh->disconnect if $dba_dbh;
 }
 
 sub _get_dbh {

commit 6bd7490c6e965525c24c81adadafe01fed403fb2
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Jan 18 10:37:18 2011 +0300

    reorder how we bootstrap plugins
    
    bootstrap paths asap
    
    set @Plugins in the config, so plugins' configs are loaded
    
    setup plugins' DB right after setting RT's DB

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 551d9c2..46b44d2 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -137,6 +137,8 @@ sub import {
 
     $class->bootstrap_tempdir;
 
+    $class->bootstrap_plugins_paths( %args );
+
     $class->bootstrap_config( %args );
 
     use RT;
@@ -154,10 +156,8 @@ sub import {
     RT::InitClasses();
     RT::InitLogging();
 
-    $class->bootstrap_plugins( %args );
-
     RT->Plugins;
-    
+
     RT::I18N->Init();
     RT->Config->PostLoadCheck;
 
@@ -410,6 +410,8 @@ sub bootstrap_db {
             $RT::Handle->InsertData( $RT::EtcPath . "/initialdata" );
             DBIx::SearchBuilder::Record::Cachable->FlushCache;
         }
+        $self->bootstrap_plugins_db( %args );
+        __reconnect_rt();
     }
 }
 

commit 8e804894ae3cd183209f9cc17d246e33104ff060
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Jan 18 10:46:07 2011 +0300

    disconnect before fork

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 46b44d2..db47451 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -1240,6 +1240,7 @@ sub start_plack_server {
              kill 'USR1' => getppid();
          });
 
+    __disconnect_rt();
     my $pid = fork();
     die "failed to fork" unless defined $pid;
 

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


More information about the Rt-commit mailing list