httpd-test-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject [patch] more robust startup + counting
Date Wed, 21 Nov 2001 15:29:16 GMT
Once in a while someone is running mod_perl on a slow machine and the
server won't start in the time given it to. And everytime we would extend
this time... Today I was running mod_perl tests on the slow notebook, and
it'd fail to start most of the time. So here is the usual patch that bumps
up the time (last time it was 6!=24 secs) to 60 secs, which should put the
end to this.

On the way, I've a little bit simplified logic and made a bit nicer user
experience, by showing the wait time. I know that before that it was
testing every 1, 2, 3, 4, ... secs. but I don't think ping is a heavy
operation for not to test every sec.

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.40
diff -u -r1.40 TestServer.pm
--- Apache-Test/lib/Apache/TestServer.pm	2001/10/22 06:15:36	1.40
+++ Apache-Test/lib/Apache/TestServer.pm	2001/11/21 15:07:50
@@ -417,7 +417,7 @@
     }

     while ($old_pid and $old_pid == $self->pid) {
-        warning "old pid file ($old_pid) still exists\n";
+        warning "old pid file ($old_pid) still exists";
         sleep 1;
     }

@@ -426,34 +426,26 @@
     $mpm = "($mpm MPM)" if $mpm;
     print "using $version $mpm\n";

-    my $tries = 6;
+    my $wait_secs = 60; # XXX: make a constant?

-    for (1..$tries) {
-        my $pid = $self->pid;
-        if ($pid) {
-            if($_ > 1) {
-                print "ok\n";
-            }
-        }
-        else {
-            if ($_ == 1) {
-                print "waiting for server to warm up...";
-            }
-            elsif ($_ > $tries) {
-                print "giving up\n";
-                last;
-            }
-            else {
-                print "...";
-            }
-            sleep $_;
-            next;
+    my $start_time = time;
+    my $preamble = "\rwaiting for server to start: ";
+    while (1) {
+        my $delta = time - $start_time;
+        print $preamble, sprintf "%02d:%02d", (gmtime $delta)[1,0];
+        sleep 1;
+        if ($self->pid) {
+            print $preamble, "ok (waited $delta secs)\n";
+            last;
+        }
+        elsif ($delta > $wait_secs) {
+            print $preamble, "giving up after $delta secs\n";
+            last;
         }
-        last;
     }

     if (my $pid = $self->pid) {
-        print "\nserver $self->{name} started\n";
+        print "server $self->{name} started\n";

         my $vh = $config->{vhosts};
         my $by_port = sub { $vh->{$a}->{port} <=> $vh->{$b}->{port} };
@@ -479,26 +471,24 @@
     if ($server_up->()) {
         return 1;
     }
-    else {
-        warning "still waiting for server to warm up...";
-        sleep 1;
-    }

-    for my $try (1..$tries) {
+    $start_time = time;
+    $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;
         if ($server_up->()) {
-            print "ok\n";
-            return 1;
-        }
-        elsif ($try >= $tries) {
-            print "giving up\n";
+            print $preamble, "ok (waited $delta secs)\n";
+            last;
         }
-        else {
-            print "...";
-            sleep $try;
+        elsif ($delta > $wait_secs) {
+            print $preamble, "giving up after $delta secs\n";
+            last;
         }
     }

-    $self->failed_msg("\nfailed to start server!");
+    $self->failed_msg("failed to start server!");
     return 0;
 }




_____________________________________________________________________
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/


Mime
View raw message