perl-test-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject [PATCH] @NextAvailablePort@ token in conf.in
Date Wed, 26 Oct 2005 21:36:05 GMT
Sometimes there is a need to dynamically allocate ports for non-vhosts 
(.e.g. if you spawn a non-Apache server used in testing that binds to some 
port). Since Apache-Test already provides a feature that allows more than 
one test suite run on the same machine at the same time by figuring out 
what are the available ports to use, (using t/TEST -port select), I 
thought we could tap into that feature and allocate the next available 
port, which can be used as either:

SetVar MyPortFoo @NextAvailablePort@

or via <Perl> sections for modperl users:

<Perl>
   my $port = @NextAvailablePort@;
   # now do something with it
</Perl>

What do you think?

The patch is trivial (could easily add a test)

Index: t/conf/extra.conf.in
===================================================================
--- t/conf/extra.conf.in        (revision 328716)
+++ t/conf/extra.conf.in        (working copy)
@@ -5,6 +5,8 @@
    Redirect /redirect http://@ServerName@/redirected/
  </IfModule>

+SetVar MyFeaturePort @NextAvailablePort@
+
  <IfModule mod_perl.c>

    <Location /TestMore__testpm>
Index: lib/Apache/TestConfig.pm
===================================================================
--- lib/Apache/TestConfig.pm    (revision 328716)
+++ lib/Apache/TestConfig.pm    (working copy)
@@ -1118,9 +1118,15 @@

      s[@(\w+)@]
       [ my $key = lc $1;
-      exists $self->{vars}->{$key}
-      ? $self->{vars}->{$key}
-      : die "invalid token: \@$1\@ $file\n";
+       if ($key eq 'nextavailableport') {
+           $self->server->select_next_port;
+       }
+       elsif (exists $self->{vars}->{$key}) {
+           $self->{vars}->{$key};
+       }
+       else {
+           die "invalid token: \@$1\@ $file\n";
+       }
       ]ge;
  }

-- 
_____________________________________________________________
Stas Bekman mailto:stas@stason.org  http://stason.org/
MailChannels: Assured Messaging(TM) http://mailchannels.com/
The "Practical mod_perl" book       http://modperlbook.org/
http://perl.apache.org/ http://perl.org/ http://logilune.com/


Mime
View raw message