Stas Bekman wrote:

Steve Hay wrote:
[...]

I suppose we could have Apache::TestSmoke::run_test() look for the "server is not running" message, and have it just warn about it rather than error and exit, but there's nearly nothing else after that anyway so we don't gain much by not exiting. In fact, if the server is not running at the end of the smoke then something has obviously gone wrong, so I think putting out an error makes sense anway.


right on. How about we delegate it to TestServer

TestServer? - this is all TestSmoke...


and simply do the same as:

    # stop server
    {
        my $command = $self->{stop_command};
        my $log = '';
        IPC::Run3::run3($command, undef, \$log, \$log);
        my $stopped_ok = ($log =~ /shutdown/) ? 1 : 0;
        unless ($stopped_ok) {
            error "failed to stop server\n $log";
            exit 1;
        }
    }

in sub kill_proc {}. in fact we can replace the above block with the new version of kill_proc, which will contain the above block.
I don't think a second kill_proc is really needed in run_test(), but it is needed in the other places in TestSmoke, so I think it'll just work.

OK, I've done that in the attached patch (same as my last one, plus this change).


There are actually only 2 other calls to kill_proc(), besides the one at the end of run_test() -- one at the start of run_test() and one in the SIGINT handler. I've had to remove the kill_proc() call from the start of run_test() because it made "t/SMOKE" fall over at the start complaining that it couldn't stop the server (because the new kill_proc() throws an error() if it couldn't do the shutdown)!

I kept the hack in kill_proc() to get at the PID file so that it can be removed, regardless of whether the shutdown succeeded (much like we've done in TestServer::stop()).

- Steve
--- TestServer.pm.orig  2003-10-10 05:05:56.000000000 +0100
+++ TestServer.pm       2003-10-16 15:15:07.522253200 +0100
@@ -12,6 +12,7 @@
 use Apache::TestRequest ();
 
 use constant COLOR => Apache::TestConfig::COLOR;
+use constant WIN32 => Apache::TestConfig::WIN32;
 
 my $CTRL_M = COLOR ? "\r" : "\n";
 
@@ -313,19 +314,17 @@
     my $self = shift;
     my $aborted = shift;
 
-    if (Apache::TestConfig::WIN32) {
-        if ($self->{config}->{win32obj}) {
-            $self->{config}->{win32obj}->Kill(0);
-            warning "server $self->{name} shutdown";
-            return 1;
+    if (WIN32) {
+        require Win32::Process;
+        my $obj = $self->{config}->{win32obj};
+        if (my $pid = $obj ? $obj->GetProcessID : $self->pid) {
+            if (kill(0, $pid)) {
+                Win32::Process::KillProcess($pid, 0);
+                warning "server $self->{name} shutdown";
+            }
         }
-        else {
-            require Win32::Process;
-            my $pid = $self->pid;
-            Win32::Process::KillProcess($pid, 0);
-            warning "server $self->{name} shutdown";
-            return 1;
-       }
+        unlink $self->pid_file if (-f $self->pid_file);
+        return 1;
     }
 
     my $pid = 0;
@@ -415,7 +414,22 @@
 
 sub start {
     my $self = shift;
-    my $old_pid = $self->stop;
+    my $old_pid = 0;
+    if (WIN32) {
+        # Stale PID files (e.g. left behind from a previous test run
+        # that crashed) cannot be trusted on Windows because PID's are
+        # re-used too frequently, so just remove it. If there is an old
+        # server still running then the attempt to start a new one below
+        # will simply fail because the port will be unavailable.
+        if (-f $self->pid_file) {
+            warn "Removing old PID file -- " .
+                "Unclean shutdown of previous test run?\n";
+            unlink $self->pid_file;
+        }
+    }
+    else {
+        $old_pid = $self->stop;
+    }
     my $cmd = $self->start_cmd;
     my $config = $self->{config};
     my $vars = $config->{vars};
@@ -436,7 +450,7 @@
     print "$cmd\n";
     my $old_sig;
 
-    if (Apache::TestConfig::WIN32) {
+    if (WIN32) {
         #make sure only 1 process is started for win32
         #else Kill will only shutdown the parent
         my $one_process = $self->version_of(\%one_process);
@@ -450,7 +464,11 @@
                                "$cmd $one_process",
                                1,
                                Win32::Process::NORMAL_PRIORITY_CLASS(),
-                               '.') || die Win32::Process::ErrorReport();
+                               '.');
+        unless ($obj) {
+            die "Could not start the server: " .
+                Win32::FormatMessage(Win32::GetLastError());
+        }
         $config->{win32obj} = $obj;
     }
     else {
--- TestSmoke.pm.orig   2003-10-10 05:05:56.000000000 +0100
+++ TestSmoke.pm        2003-10-16 15:45:02.195146700 +0100
@@ -189,9 +189,6 @@
 sub run {
     my($self) = shift;
 
-    # make sure that there the server is down
-    $self->kill_proc();
-
     $self->Apache::TestRun::warn_core();
     local $SIG{INT};
     $self->install_sighandlers;
@@ -577,18 +574,6 @@
     $self->logs_end();
 
     # stop server
-    {
-        my $command = $self->{stop_command};
-        my $log = '';
-        IPC::Run3::run3($command, undef, \$log, \$log);
-        my $stopped_ok = ($log =~ /shutdown/) ? 1 : 0;
-        unless ($stopped_ok) {
-            error "failed to stop server\n $log";
-            exit 1;
-        }
-    }
-
-    # double check that we killed them all?
     $self->kill_proc();
 
     if ($self->{bug_mode}) {
@@ -719,16 +704,21 @@
 sub kill_proc {
     my($self) = @_;
 
-    # a hack
+    my $command = $self->{stop_command};
+    my $log = '';
+    require IPC::Run3;
+    IPC::Run3::run3($command, undef, \$log, \$log);
+
+    # remove the PID file whether the stop succeeded or not
     my $t_logs  = $self->{test_config}->{vars}->{t_logs};
     my $file = catfile $t_logs, "httpd.pid";
-    return unless -f $file;
-
-    my $pid = `cat $file`;
-    chomp $pid;
-    return unless $pid;
+    unlink $file if -f $file;
 
-    kill SIGINT => $pid;
+    my $stopped_ok = ($log =~ /shutdown/) ? 1 : 0;
+    unless ($stopped_ok) {
+        error "failed to stop server\n $log";
+        exit 1;
+    }
 }
 
 sub opt_help {

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to