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...
I meant that Smoke shouldn't mess at all with httpd.pid file and delegate it to Server. Smoke should just say 'stop' and Server should do the right thing. The updated patch is at the bottom.
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).
Cool.
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()).
OK, I tried to expand the unlink code to the rest of the OSes, so here your patch with a few small tweaks. Please check that I didn't break anything. Thanks.
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.67
diff -u -r1.67 TestServer.pm
--- Apache-Test/lib/Apache/TestServer.pm 10 Oct 2003 04:05:56 -0000 1.67
+++ Apache-Test/lib/Apache/TestServer.pm 16 Oct 2003 22:58:21 -0000
@@ -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,18 @@
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};
+ my $pid = -1;
+ if ($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 -e $self->pid_file;
+ return $pid;
}my $pid = 0; @@ -345,7 +345,10 @@
for (1..6) {
if (! $self->ping) {
- return $pid if $_ == 1;
+ if ($_ == 1) {
+ unlink $self->pid_file if -e $self->pid_file;
+ return $pid;
+ }
last;
}
if ($_ == 1) {
@@ -380,10 +383,12 @@
if (--$tries <= 0) {
error "cannot shutdown server on Port $port, ".
"please shutdown manually";
+ unlink $self->pid_file if -e $self->pid_file;
return -1;
}
}+ unlink $self->pid_file if -e $self->pid_file;
return $pid;
}@@ -415,7 +420,23 @@
sub start {
my $self = shift;
- my $old_pid = $self->stop;
+
+ my $old_pid = -1;
+ 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) {
+ error "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 +457,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 +471,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 {
Index: Apache-Test/lib/Apache/TestSmoke.pm
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestSmoke.pm,v
retrieving revision 1.24
diff -u -r1.24 TestSmoke.pm
--- Apache-Test/lib/Apache/TestSmoke.pm 10 Oct 2003 04:05:56 -0000 1.24
+++ Apache-Test/lib/Apache/TestSmoke.pm 16 Oct 2003 22:58:22 -0000
@@ -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,15 @@
sub kill_proc {
my($self) = @_;- # a hack
- 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;
+ my $command = $self->{stop_command};
+ my $log = '';
+ require IPC::Run3;
+ IPC::Run3::run3($command, undef, \$log, \$log);- kill SIGINT => $pid;
+ my $stopped_ok = ($log =~ /shutdown/) ? 1 : 0;
+ unless ($stopped_ok) {
+ error "failed to stop server\n $log";
+ }
}sub opt_help {
__________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
