hi all...

has anyone given any thought to adding an API whereby a test can issue a server restart? I'd like to be able to do this in order to test code that takes action when the server is restarted (clearing caches, updating Last-Modified, etc), but I'm sure there could be other uses if the API gets written in.

I whipped up something quick that sorta works on unix (2.0 seem to be ok on linux, but 1.3 has trouble when request.t immediately follows ping.t - maybe not checking something right), but if people think it's a good idea then this could serve as a starting point for something more portable (Win32, etc)...

--Geoff

Index: t/ping.t
===================================================================
RCS file: /home/cvspublic/httpd-test/perl-framework/Apache-Test/t/ping.t,v
retrieving revision 1.2
diff -u -r1.2 ping.t
--- t/ping.t    10 Sep 2001 17:12:37 -0000      1.2
+++ t/ping.t    28 Oct 2002 20:25:17 -0000
@@ -3,7 +3,7 @@

 use Apache::Test;

-plan tests => 3;
+plan tests => 4;

 my $config = Apache::Test::config();

@@ -14,4 +14,6 @@
 ok $server;

 ok $server->ping;
+
+ok $server->restart;

Index: lib/Apache/TestServer.pm
===================================================================
RCS file: 
/home/cvspublic/httpd-test/perl-framework/Apache-Test/lib/Apache/TestServer.pm,v
retrieving revision 1.60
diff -u -r1.60 TestServer.pm
--- lib/Apache/TestServer.pm    1 Jul 2002 08:11:50 -0000       1.60
+++ lib/Apache/TestServer.pm    28 Oct 2002 20:25:17 -0000
@@ -511,6 +511,32 @@
     return 0;
 }

+sub restart {
+    my $self = shift;
+    my $pid = $self->pid;
+
+    if (Apache::TestConfig::WIN32) {
+      # do something Win32 specific here
+    }
+    else {
+      # unix variant
+      if (kill HUP => $pid) {
+        warning "server $self->{name} restarted";
+      }
+      else {
+        error "kill -HUP $pid failed: $!";
+        $self->failed_msg("failed to restart server!");
+        return 0;
+      }
+    }
+
+    my $timeout = 60; # secs XXX: make a constant?
+
+    return 1 if $self->wait_till_is_up($timeout);
+
+    $self->failed_msg("failed to restart server!");
+    return 0;
+}

 # wait till the server is up and return 1
 # if the waiting times out returns 0



Reply via email to