This patch
- picks the next available port during the configuration
- reconfigures the server at run time if after configuration, the port is
  found to be used.

Now I can rebuild and test in many checkout out copies at the same time,
without wasting time specifying different port numbers for different
builds. The cool thing about my patch, that it reconfigures itself, if
somebody else took over the port after the server was configured.

I've also had to fix stop() since it's OK if it tries to stop, and the
configured port is used, but there is no pid file.

issues:
- is it a warning or an error, when we report that we use a different port?
- default_port() is called 3 times after -clean, should I memoize the
  value on the first call and return it without going through the checking
  and warnings printing again and again. I think I must, since it's
  possible that the default port will be released in between the calls,
  and then the configuration will be broken as different places will use
  different ports.

Index: Apache-Test/lib/Apache/TestConfig.pm
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestConfig.pm,v
retrieving revision 1.69
diff -u -r1.69 TestConfig.pm
--- Apache-Test/lib/Apache/TestConfig.pm        2001/10/05 23:44:16     1.69
+++ Apache-Test/lib/Apache/TestConfig.pm        2001/10/06 07:57:15
@@ -463,9 +463,31 @@
     $localhost ||= $self->default_localhost;
 }

-#XXX: could check if the port is in use and select another if so
 sub default_port {
-    $ENV{APACHE_PORT} || 8529;
+    # don't check availability in this case
+    return $ENV{APACHE_PORT} if exists $ENV{APACHE_PORT};
+
+    # return the default port if it is available
+    my $default_port  = 8529;
+    return $default_port
+        if Apache::TestServer->port_available($default_port);
+
+    # try to find another available port, take into account that each
+    # instance of test suite may use more than one port for virtual
+    # hosts, therefore try to check ports in big steps (50?).
+    my $step  = 50;
+    my $port  = $default_port + $step;
+    my $tries = 20;
+    until (Apache::TestServer->port_available($port)) {
+        unless (--$tries) {
+            error "no ports available";
+            error "tried ports from 8529 to $port in $step jumps";
+            return 0;
+        }
+        $port += $step;
+    }
+    error "port $default_port is used, using port $port instead";
+    return $port;
 }

 sub default_loopback {
Index: Apache-Test/lib/Apache/TestRun.pm
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestRun.pm,v
retrieving revision 1.52
diff -u -r1.52 TestRun.pm
--- Apache-Test/lib/Apache/TestRun.pm   2001/09/22 07:21:58     1.52
+++ Apache-Test/lib/Apache/TestRun.pm   2001/10/06 07:57:15
@@ -267,6 +267,15 @@
         $ENV{APACHE_TEST_HTTP11} = 1;
     }

+    my $server = $test_config->server;
+    my $port   = $test_config->{vars}->{port};
+    unless ($server->port_available($port)) {
+        warning "the port $port is in use, reconfiguring";
+        $self->refresh;
+        $refreshed = 1;
+        $test_config = $self->{test_config};
+    }
+
     if (my @reasons = $self->{test_config}->need_reconfiguration) {
         warning "forcing re-configuration:";
         warning "\t- $_." for @reasons;
Index: Apache-Test/lib/Apache/TestServer.pm
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestServer.pm,v
retrieving revision 1.32
diff -u -r1.32 TestServer.pm
--- Apache-Test/lib/Apache/TestServer.pm        2001/09/19 11:12:06     1.32
+++ Apache-Test/lib/Apache/TestServer.pm        2001/10/06 07:57:16
@@ -264,12 +264,17 @@
     my $self = shift;
     my $aborted = shift;

-    my $pid = 0;
+    my $pid = $self->pid || 0;
     my $tries = 3;
     my $tried_kill = 0;

     my $port = $self->{config}->{vars}->{port};

+    unless ($pid) {
+        warning "no server is running";
+        return 0;
+    }
+
     while ($self->ping) {
         #my $state = $tried_kill ? "still" : "already";
         #print "Port $port $state in use\n";
@@ -306,11 +311,6 @@
             else {
                 error "kill $pid failed: $!";
             }
-        }
-        else {
-            error "port $port is in use, ".
-                  "cannot determine server pid to shutdown";
-            return -1;
         }

         if (--$tries <= 0) {


_____________________________________________________________________
Stas Bekman             JAm_pH      --   Just Another mod_perl Hacker
http://stason.org/      mod_perl Guide   http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to