You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-dev@perl.apache.org by Stas Bekman <st...@stason.org> on 2005/10/26 23:36:05 UTC
[PATCH] @NextAvailablePort@ token in conf.in
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/
Re: [PATCH] @NextAvailablePort@ token in conf.in
Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
>>SetVar MyPortFoo @NextAvailablePort@
>
>
>>What do you think?
>
>
> sounds like a good idea
The reason I was hesitating about going ahead with it, is that I'd love to
have a way to figure out what was that port number at run time (unless the
directive took care of it). e.g. with vhost we can get the port number by
supplying the vhost's name. But I couldn't think of a similar way for this
feature. May be it could be something like:
SetVar MyPortFoo @NextAvailablePort:foo_port@
and have Apache::Test store that info, and let for example the client side
access that info by passing foo_port as an identifier?
>>+ if ($key eq 'nextavailableport') {
>>+ $self->server->select_next_port;
>>+ }
>
>
> rather than hard-coding an exception, maybe use some type of coderef map?
>
> my $non_var_tokens = {
> nextavailableport => $self->server->can('select_next_port'),
> };
>
> or somesuch?
Sure
> but +1 on whatever you come up with - this is goodness :)
Thanks.
--
_____________________________________________________________
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/
Re: [PATCH] @NextAvailablePort@ token in conf.in
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> SetVar MyPortFoo @NextAvailablePort@
> What do you think?
sounds like a good idea
> + if ($key eq 'nextavailableport') {
> + $self->server->select_next_port;
> + }
rather than hard-coding an exception, maybe use some type of coderef map?
my $non_var_tokens = {
nextavailableport => $self->server->can('select_next_port'),
};
or somesuch?
but +1 on whatever you come up with - this is goodness :)
--Geoff