[Rt-commit] r9065 - rt/branches/3.7-EXPERIMENTAL/lib/RT

ruz at bestpractical.com ruz at bestpractical.com
Sat Sep 15 19:32:01 EDT 2007


Author: ruz
Date: Sat Sep 15 19:32:01 2007
New Revision: 9065

Modified:
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Test.pm

Log:
* generate port/dbname in the BEGIN block as import, otherwise
  we the config may be wrong
* move the sub as it's required in the BEGIN block, so it should be
  compiled intime

Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Test.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Test.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Test.pm	Sat Sep 15 19:32:01 2007
@@ -10,6 +10,22 @@
 our ($existing_server, $port, $dbname);
 my $mailsent;
 
+sub generate_port {
+    my $self = shift;
+    my $port = 1024 + int rand(10000) + $$ % 1024;
+
+    my $paddr = sockaddr_in( $port, inet_aton('localhost') );
+    socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp') )
+      or die "socket: $!";
+    if ( connect( SOCK, $paddr ) ) {
+        close(SOCK);
+        return generate_port();
+    }
+    close(SOCK);
+
+    return $port;
+}
+
 BEGIN {
     if ( my $test_server = $ENV{'RT_TEST_SERVER'} ) {
         my ($host, $test_port) = split(':', $test_server, 2);
@@ -19,6 +35,16 @@
         # we can't parallel test with $existing_server
         undef $ENV{RT_TEST_PARALLEL};
     }
+    if ( $ENV{RT_TEST_PARALLEL} ) {
+        $port   = generate_port();
+        $dbname = "rt3test_$port";    #yes, dbname also makes use of $port
+    }
+    else {
+        $dbname = "rt3test";
+    }
+
+    $port = generate_port() unless $port;
+
 };
 
 use RT::Interface::Web::Standalone;
@@ -29,16 +55,6 @@
 
 my @server;
 
-if ( $ENV{RT_TEST_PARALLEL} ) {
-    $port   = generate_port();
-    $dbname = "rt3test_$port";    #yes, dbname also makes use of $port
-}
-else {
-    $dbname = "rt3test";
-}
-
-$port = generate_port() unless $port;
-
 sub import {
     my $class = shift;
     my %args = @_;
@@ -591,22 +607,6 @@
     return %res;
 }
 
-sub generate_port {
-    my $self = shift;
-    my $port = 1024 + int rand(10000) + $$ % 1024;
-
-    my $paddr = sockaddr_in( $port, inet_aton('localhost') );
-    socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp') )
-      or die "socket: $!";
-    if ( connect( SOCK, $paddr ) ) {
-        close(SOCK);
-        return generate_port();
-    }
-    close(SOCK);
-
-    return $port;
-}
-
 END {
     if ( $ENV{RT_TEST_PARALLEL} && $created_new_db ) {
         my $dbh =


More information about the Rt-commit mailing list