Stas Bekman wrote:
Steve Hay wrote:
I notice that running tests via nmake test, t/TEST or t/SMOKE leaves a httpd.pid file behind in t/logs after the server has stopped. Is this supposed to happen? I thought Apache normally deleted the httpd.pid file when it is stopped.
That's not under Apache-Test's control, it's Apache who manages this file, we aren't supposed to touch it. All we do is reading the pid from it.
Well that's odd then, because when I start & stop my installed Apache2 server myself, the httpd.pid file that it creates in C:\apache2\logs *does* get deleted. I wonder why that doesn't happen to mp2's t\logs\httpd.pid when the testing code starts & stops it?
Don't know why I didn't see this before, but the answer is obvious, isn't it? - The PID file doesn't get removed because mp2's testing code *kills*, rather than *stops*, Apache!
If I manually start & stop Apache with:
apache.exe -k start apache.exe -k stop
then the PID file is deleted, but if I just start Apache as above and then *kill* it (say, using TaskManager) then the PID file is of course left behind.
TestServer::stop() has this code in it for Windows:
if (Apache::TestConfig::WIN32) {
if ($self->{config}->{win32obj}) {
$self->{config}->{win32obj}->Kill(0);
warning "server $self->{name} shutdown";
return 1;
}
else {
require Win32::Process;
my $pid = $self->pid;
Win32::Process::KillProcess($pid, 0);
warning "server $self->{name} shutdown";
return 1;
}
}If I change the two warnings above to number them 1 and 2, and output the PID in the second case as well, then running "perl t/TEST modperl\post_utf8" outputs this:
C:\Temp\modperl-2.0>perl t/TEST modperl\post_utf8 *** server localhost:8529 shutdown 2 (pid 0) [...] *** server localhost:8529 shutdown 1
when there is no existing PID file, and something like:
C:\Temp\modperl-2.0>perl t/TEST modperl\post_utf8 *** server localhost:8529 shutdown 2 (pid 2128) [...] *** server localhost:8529 shutdown 1
when there is.
In each case the "shutdown 1" at the end of the test run is OK (... except that it is kill rather than something more graceful) - it's killing the process that it has an object for, which is at least the "right" process to be killing.
But in each case the "shutdown 2" at the start of the test run is wrong. When the PID doesn't exist $self->{pid} is evidently 0, so there's no point in trying to kill it; and when the PID file does exist it most likely relates to an earlier test run, the Apache process for which has long since gone away because we killed it at the end of that run.
Can we change the stop() called at the end of the test run to try to stop Apache "gracefully" first, and only try to kill it if that fails?
Then we could perhaps change the stop() called at the start of the test run to just warn if there is a PID file left behind, indicating an ungraceful failure last time, but not actually try to kill that process since that is too risky. (Or perhaps it could still try to kill it, but use the Win32::Process::Info code that I posted before to first check that the PID is our Apache if we are on Windows -- if we're not on Windows then maybe there is no need for such a check since PIDs are not re-used so quickly on non-Windows OS's anyway?)
I don't know how to do the "graceful" stop, though. What we want is a bit like trying TERM then KILL on Unix, but that doesn't work on Win32 -- see the entry for kill() in the perlport manpage! Win32::Process doesn't have any "graceful" kill options either, and the "apache.exe -k stop" command-line that I mentioned above only relates to installed Apache2 *services*, not processes started from a command shell. Any ideas, Randy?
- Steve
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
