httpd-test-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject cvs commit: httpd-test/perl-framework/Apache-Test Changes
Date Mon, 20 Oct 2003 20:09:05 GMT
stas        2003/10/20 13:09:05

  Modified:    perl-framework/Apache-Test/lib/Apache TestRun.pm
                        TestServer.pm TestSmoke.pm
               perl-framework/Apache-Test Changes
  Log:
  TestRun was using httpd.pid file to ensure that the server is killed
  before starting it, if the file existed. This was a problem on win32
  platforms, where a process scheduler tries to re-use the pids that
  were just freed, which may have killed a valid process which is not
  even Apache.exe. So we try not to rely on that file, and if the server
  wasn't properly stopped and still running, users will learn about
  that, since the port will be busy, and Apache will fail to
  start. Users have to kill it manually. TestSmoke is no longer using an
  explicit kill `cat httpd.pid` to stop Apache, but delegates the
  stopping procedure to TestRun
  Submitted by:	Steve Hay, Randy Kobes
  
  Revision  Changes    Path
  1.116     +4 -0      httpd-test/perl-framework/Apache-Test/lib/Apache/TestRun.pm
  
  Index: TestRun.pm
  ===================================================================
  RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestRun.pm,v
  retrieving revision 1.115
  retrieving revision 1.116
  diff -u -u -r1.115 -r1.116
  --- TestRun.pm	1 Oct 2003 18:32:26 -0000	1.115
  +++ TestRun.pm	20 Oct 2003 20:09:05 -0000	1.116
  @@ -427,6 +427,10 @@
           }
           else {
               warning "server $self->{server}->{name} is not running";
  +            # cleanup a stale httpd.pid file if found
  +            my $t_logs  = $self->{test_config}->{vars}->{t_logs};
  +            my $pid_file = catfile $t_logs, "httpd.pid";
  +            unlink $pid_file if -e $pid_file;
           }
           exit_perl $ok;
       }
  
  
  
  1.68      +42 -16    httpd-test/perl-framework/Apache-Test/lib/Apache/TestServer.pm
  
  Index: TestServer.pm
  ===================================================================
  RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestServer.pm,v
  retrieving revision 1.67
  retrieving revision 1.68
  diff -u -u -r1.67 -r1.68
  --- TestServer.pm	10 Oct 2003 04:05:56 -0000	1.67
  +++ TestServer.pm	20 Oct 2003 20:09:05 -0000	1.68
  @@ -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,24 @@
   
   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;
  +        }
  +        $old_pid = 0;
  +    }
  +    else {
  +        $old_pid = $self->stop;
  +    }
       my $cmd = $self->start_cmd;
       my $config = $self->{config};
       my $vars = $config->{vars};
  @@ -436,7 +458,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 +472,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 {
  
  
  
  1.25      +8 -24     httpd-test/perl-framework/Apache-Test/lib/Apache/TestSmoke.pm
  
  Index: TestSmoke.pm
  ===================================================================
  RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestSmoke.pm,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -u -r1.24 -r1.25
  --- TestSmoke.pm	10 Oct 2003 04:05:56 -0000	1.24
  +++ TestSmoke.pm	20 Oct 2003 20:09:05 -0000	1.25
  @@ -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 {
  
  
  
  1.53      +11 -0     httpd-test/perl-framework/Apache-Test/Changes
  
  Index: Changes
  ===================================================================
  RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/Changes,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -u -r1.52 -r1.53
  --- Changes	10 Oct 2003 04:05:56 -0000	1.52
  +++ Changes	20 Oct 2003 20:09:05 -0000	1.53
  @@ -8,6 +8,17 @@
   
   =item 1.05-dev
   
  +TestRun was using httpd.pid file to ensure that the server is killed
  +before starting it, if the file existed. This was a problem on win32
  +platforms, where a process scheduler tries to re-use the pids that
  +were just freed, which may have killed a valid process which is not
  +even Apache.exe. So we try not to rely on that file, and if the server
  +wasn't properly stopped and still running, users will learn about
  +that, since the port will be busy, and Apache will fail to
  +start. Users have to kill it manually. TestSmoke is no longer using an
  +explicit kill `cat httpd.pid` to stop Apache, but delegates the
  +stopping procedure to TestRun [Steve Hay, Randy Kobes]
  +
   use IPC::Run3 in Apache::TestSmoke to run t/TEST commands,
   so as t/SMOKE can be used on Win32 [Stas, Steve Hay, Randy Kobes]
   
  
  
  

Mime
View raw message