You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-dev@httpd.apache.org by Stas Bekman <st...@stason.org> on 2001/11/22 17:23:13 UTC

[patch] adding the startup polling functionality

I've figured out that I have to run many times t/TEST -run
until it successfully pings the server under t/TEST -d, so I want the
polling functionality for -run too. Since now we have 3 places where the
polling happens (start/ping/run), this patch:

- refactors the polling code into Apache::TestServer::wait_till_is_up()
- adds -poll option which will block until the server starts for -ping and
  -run opts. (which takes over the -ping=block which I've added this
  morning).

issues:
- any reason for not making -poll turned on by default for -run?

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.69
diff -u -r1.69 TestRun.pm
--- Apache-Test/lib/Apache/TestRun.pm	2001/11/22 03:11:38	1.69
+++ Apache-Test/lib/Apache/TestRun.pm	2001/11/22 15:59:10
@@ -14,11 +14,13 @@
 use Getopt::Long qw(GetOptions);
 use Config;

+use constant STARTUP_TIMEOUT => 300; # secs (good for extreme debug cases)
+
 my @std_run      = qw(start-httpd run-tests stop-httpd);
-my @others       = qw(verbose configure clean help ssl http11);
+my @others       = qw(verbose configure clean help ping poll ssl http11);
 my @flag_opts    = (@std_run, @others);
 my @string_opts  = qw(order);
-my @ostring_opts = qw(proxy ping);
+my @ostring_opts = qw(proxy);
 my @debug_opts   = qw(debug);
 my @num_opts     = qw(times);
 my @list_opts    = qw(preamble postamble breakpoint);
@@ -39,7 +41,8 @@
    'help'            => 'display this message',
    'preamble'        => 'config to add at the beginning of httpd.conf',
    'postamble'       => 'config to add at the end of httpd.conf',
-   'ping[=block]'    => 'test if server is running or port in use',
+   'ping'            => 'test if server is running or port in use',
+   'poll'            => 'poll the server until it starts',
    'debug[=name]'    => 'start server under debugger name (e.g. gdb, ddd, ...)',
    'breakpoint=bp'   => 'set breakpoints (multiply bp can be set)',
    'header'          => "add headers to (".join('|', @request_opts).") request",
@@ -202,6 +205,12 @@
         $opts{debug} = 1;
     }

+    # -poll should be used only with -run-tests or -ping
+    if ( $opts{poll} && !($opts{'run-tests'} || $opts{ping}) ) {
+        error "-poll is valid only with either -run-tests or -ping";
+        exit;
+    }
+
     # breakpoint automatically turns the debug mode on
     if (@{ $opts{breakpoint} }) {
         $opts{debug} ||= 1;
@@ -416,7 +425,9 @@
         exit 1 unless $server->start;
     }
     elsif ($opts->{'run-tests'}) {
-        if (!$server->ping) {
+        my $is_up = $server->ping ||
+            ($self->{opts}->{poll} && $server->wait_till_is_up(STARTUP_TIMEOUT));
+        unless ($is_up) {
             error "server is not ready yet, try again.";
             exit;
         }
@@ -634,24 +645,8 @@
         return 1;
     }

-    my $opt = $self->{opts}->{ping} || '';
-    if ($opt eq 'block') {
-        my $wait_secs = 300; # should be enough for extreme debug cases
-        my $start_time = time;
-        my $preamble = "\rwaiting for server $name to come up: ";
-        while (1) {
-            my $delta = time - $start_time;
-            print $preamble, sprintf "%02d:%02d", (gmtime $delta)[1,0];
-            sleep 1;
-            if ($server->ping) {
-                print $preamble, "\rserver $name is now up (waited $delta secs)    \n";
-                last;
-            }
-            elsif ($delta > $wait_secs) {
-                print $preamble, "giving up after $delta secs\n";
-                last;
-            }
-        }
+    if ($self->{opts}->{poll}) {
+        $server->wait_till_is_up(STARTUP_TIMEOUT);
     }
     else {
         warning "no server is running on $name";
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.41
diff -u -r1.41 TestServer.pm
--- Apache-Test/lib/Apache/TestServer.pm	2001/11/22 03:13:04	1.41
+++ Apache-Test/lib/Apache/TestServer.pm	2001/11/22 15:59:10
@@ -426,7 +426,7 @@
     $mpm = "($mpm MPM)" if $mpm;
     print "using $version $mpm\n";

-    my $wait_secs = 60; # XXX: make a constant?
+    my $timeout = 60; # secs XXX: make a constant?

     my $start_time = time;
     my $preamble = "\rwaiting for server to start: ";
@@ -438,7 +438,7 @@
             print $preamble, "ok (waited $delta secs)\n";
             last;
         }
-        elsif ($delta > $wait_secs) {
+        elsif ($delta > $timeout) {
             print $preamble, "giving up after $delta secs\n";
             last;
         }
@@ -463,6 +463,20 @@
         return 0;
     }

+    $self->wait_till_is_up($timeout) && return 1;
+
+    $self->failed_msg("failed to start server!");
+    return 0;
+}
+
+
+# wait till the server is up and return 1
+# if the waiting times out returns 0
+sub wait_till_is_up {
+    my($self, $timeout) = @_;
+    my $config = $self->{config};
+    my $sleep_interval = 1; # secs
+
     my $server_up = sub {
         local $SIG{__WARN__} = sub {}; #avoid "cannot connect ..." warnings
         $config->http_raw_get('/index.html');
@@ -472,24 +486,21 @@
         return 1;
     }

-    $start_time = time;
-    $preamble = "\rstill waiting for server to warm up: ";
+    my $start_time = time;
+    my $preamble = "\rstill waiting for server to warm up: ";
     while (1) {
         my $delta = time - $start_time;
         print $preamble, sprintf "%02d:%02d", (gmtime $delta)[1,0];
-        sleep 1;
+        sleep $sleep_interval;
         if ($server_up->()) {
-            print $preamble, "ok (waited $delta secs)\n";
-            last;
+            print "\rthe server is up (waited $delta secs)             \n";
+            return 1;
         }
-        elsif ($delta > $wait_secs) {
-            print $preamble, "giving up after $delta secs\n";
-            last;
+        elsif ($delta > $timeout) {
+            print "\rthe server is down, giving up after $delta secs\n";
+            return 0;
         }
     }
-
-    $self->failed_msg("failed to start server!");
-    return 0;
 }

 1;

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


Re: [patch] adding the startup polling functionality

Posted by Stas Bekman <st...@stason.org>.
Gary Benson wrote:

> We used to use File::Tail to look for the "resuming normal operations" in
> the logfile; I mentioned putting this in httpd-test a while back but it
> was felt to be non-optimal due to the fact that File::Tail is not a
> standard module.

ok, but my patch does this in a portable way.

I'm also thinking to write a new apachectl that will poll untill the 
server is up and only then reports that it's up. The current apachectl 
script is absolutely unreliable. Especially when you 'restart'.


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


Re: [patch] adding the startup polling functionality

Posted by Gary Benson <gb...@redhat.com>.
We used to use File::Tail to look for the "resuming normal operations" in
the logfile; I mentioned putting this in httpd-test a while back but it
was felt to be non-optimal due to the fact that File::Tail is not a
standard module.

Gary

[ gbenson@redhat.com ][ GnuPG 85A8F78B ][ http://inauspicious.org/ ]


Re: [patch] adding the startup polling functionality

Posted by Doug MacEachern <do...@covalent.net>.
On Wed, 5 Dec 2001, Stas Bekman wrote:
 
> with mnemonic: block until ping and then run? the problem is that ping 
> is an exit option, will have to change things a bit.

minor change, see recent commit.
 
> I still like the new -poll option, since in the future we may extend 
> other options functionalities to poll too.

let's wait to see if we really need it.



Re: [patch] adding the startup polling functionality

Posted by Stas Bekman <st...@stason.org>.
Doug MacEachern wrote:

> On Wed, 5 Dec 2001, Stas Bekman wrote:
>  
> 
>>I didn't suggest to change how the default -run works (see the patch). 
>>
> 
> but you did ask:
> "- any reason for not making -poll turned on by default for -run?"


sorry, I've missed this one.


>>I've suggested a new option -poll, which when used will poll the server 
>>till it starts. since it's the same as -ping=block for ping, I've 
>>removed the =block part.
> 
> right.  i suggested making '-ping=block -run' work as expected rather than
> adding a new -poll option.


with mnemonic: block until ping and then run? the problem is that ping 
is an exit option, will have to change things a bit.

I still like the new -poll option, since in the future we may extend 
other options functionalities to poll too.

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


Re: [patch] adding the startup polling functionality

Posted by Doug MacEachern <do...@covalent.net>.
On Wed, 5 Dec 2001, Stas Bekman wrote:
 
> I didn't suggest to change how the default -run works (see the patch). 

but you did ask:
"- any reason for not making -poll turned on by default for -run?"

> I've suggested a new option -poll, which when used will poll the server 
> till it starts. since it's the same as -ping=block for ping, I've 
> removed the =block part.

right.  i suggested making '-ping=block -run' work as expected rather than
adding a new -poll option.


Re: [patch] adding the startup polling functionality

Posted by Stas Bekman <st...@stason.org>.
Doug MacEachern wrote:

> On Fri, 23 Nov 2001, Stas Bekman wrote:
> 
> 
>>I've figured out that I have to run many times t/TEST -run
>>until it successfully pings the server under t/TEST -d, so I want the
>>polling functionality for -run too. Since now we have 3 places where the
>>polling happens (start/ping/run), this patch:
>>
> 
> i like -run the way it is because it doesn't actually send any requests to
> the server, just uses ->ping.  i've been using this for profiling for
> example: t/TEST -times 10 -run t/ssl/verify 2
> 
> i don't want the /index.html request included in the profile data.
> 
> i also often do:
> 
> t/TEST -d lwp -run > test.log
> 
> and don't want extra "waiting for server ..." output in the log.
> 
> and would rather not see a new -poll option.
> can you make t/TEST -ping=block -run ... work for the functionality
> you're after?

I didn't suggest to change how the default -run works (see the patch). 
I've suggested a new option -poll, which when used will poll the server 
till it starts. since it's the same as -ping=block for ping, I've 
removed the =block part.

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


Re: [patch] adding the startup polling functionality

Posted by Doug MacEachern <do...@covalent.net>.
On Fri, 23 Nov 2001, Stas Bekman wrote:

> I've figured out that I have to run many times t/TEST -run
> until it successfully pings the server under t/TEST -d, so I want the
> polling functionality for -run too. Since now we have 3 places where the
> polling happens (start/ping/run), this patch:

i like -run the way it is because it doesn't actually send any requests to
the server, just uses ->ping.  i've been using this for profiling for
example: t/TEST -times 10 -run t/ssl/verify 2

i don't want the /index.html request included in the profile data.

i also often do:

t/TEST -d lwp -run > test.log

and don't want extra "waiting for server ..." output in the log.

and would rather not see a new -poll option.
can you make t/TEST -ping=block -run ... work for the functionality
you're after?