-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Stas Bekman wrote:
| Unfortunately we can't have a test for this, since if the test | suite doesn't start, we have a problem :( There should be a special | small test suite for that I suppose.
I've cobbled the following together for this purpose, see below. It's quite ugly but it appears to work.
| I know Philippe is moving ships at the moment, so it might be some | time before he replies, but I'll put it on the TODO list, so it | doesn't fall between chairs.
Maybe Philippe could factor out something like my "Apache::TempTestConfig" package, only better? (IMHO Apache::TestServer needs to be better decoupled from the rest of Apache::Test in order to check cleanly for Apache startup failures).
Regards,
====== t/badsyntax.t ====
use strict; use warnings FATAL => 'all';
use Apache::Test; use Apache::TestServer; use Apache::TestConfigPerl; use IO::Socket::INET;
{ ~ # This class is a copy-cat of "Apache::TestConfig" with no ~ # persistence, better suited to running temporary instances of ~ # Apache. ~ package Apache::TempTestConfig; ~ use IO::Socket::INET; ~ use base 'Apache::TestConfig';
~ sub new { ~ my ($class, $uniquename) = @_;
~ my %vars = %{Apache::TestConfig->thaw()->{vars}}; ~ delete $vars{thaw};
~ my $self = $class->SUPER::new ~ (%vars, ~ port => "select", # Get out of the way of other instances ~ t_logs => $vars{t_logs}."/$uniquename-httpd", ~ t_conf_file => $vars{t_conf}."/$uniquename-httpd.conf"); ~ $self->httpd_config(); # Can be done immediately, we know ~ # everything we need. ~ $self->configure_libmodperl(); ~ $self; ~ }
~ # Disable persistence. ~ sub custom_config_first_time { die } ~ sub custom_config_save { }
~ # Disable the standard included files ~ sub generate_extra_conf { [] }
~ # Lifted from $self->server()->start(), adapted so as not to be as ~ # picky when server fails starting ('cause in some cases that's ~ # actually what we want to test) ~ my %one_process = (1 => '-X', 2 => '-D ONE_PROCESS'); ~ sub server_start { ~ my ($self, $timeout) = @_; ~ $timeout ||= 5; ~ my $server=$self->server();
~ my $cmd = $server->start_cmd; ~ my $vars = $self->{vars}; ~ my $httpd = $vars->{httpd} || 'unknown'; ~ if (Apache::TestConfig::WIN32) { ~ #make sure only 1 process is started for win32 ~ #else Kill will only shutdown the parent ~ my $one_process = $server->version_of(\%one_process); ~ require Win32::Process; ~ my $obj; ~ # We need the "1" below to inherit the calling processes ~ # handles when running Apache::TestSmoke so as to properly ~ # dup STDOUT/STDERR ~ Win32::Process::Create($obj, ~ $httpd, ~ "$cmd $one_process", ~ 1,
Win32::Process::NORMAL_PRIORITY_CLASS(), ~ '.'); ~ unless ($obj) { ~ warn "Could not start the server: " . ~ Win32::FormatMessage(Win32::GetLastError()); ~ return 0; ~ } ~ $self->{win32obj} = $obj; ~ }
~ defined(my $pid = fork) or die "Can't fork: $!"; ~ unless ($pid) { # child ~ exec "$cmd" or do { ~ my $status = $? >> 8; ~ #error "httpd didn't start! $status"; ~ CORE::exit ($status); ~ }; ~ }
~ my $port = $self->select_first_port(); ~ for(my $i=0; $i < $timeout; $i++, sleep(1)) { ~ return 1 if (IO::Socket::INET->new(PeerHost=>"localhost", ~ PeerPort=>$port)); ~ } ~ return 0; ~ }
~ # Waits for the server to *really* be stopped. ~ sub server_stop { ~ my ($self) = @_; ~ $self->server()->stop(); ~ sleep(1) while ($self->server()->ping() || ~ IO::Socket::INET->new ~ (PeerHost=>"localhost", ~ PeerPort=>$self->select_first_port())); ~ } } # End of package Apache::TempTestConfig
plan tests => 2;
my $config = new Apache::TempTestConfig("runtimeerror"); $config->server_stop(); $config->postamble("<Perl> use Apache2; die; 1; </Perl> "); $config->generate_httpd_conf;
$config->server_stop(); ok(! $config->server_start());
$config = new Apache::TempTestConfig("badsyntax"); $config->postamble("<Perl> use Apache2; })] BAD SYNTAX })] 1; </Perl> "); $config->generate_httpd_conf;
sleep(2); ok(! $config->server_start()); $config->server_stop();
- -- Dominique QUATRAVAUX Ingénieur senior 01 44 42 00 08 IDEALX
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCKKmcMJAKAU3mjcsRAjSdAJ99faH4zgD5W1poFK/oyj+hkgHZEgCfQzGo v2vgmszFeC2ydP4W2E9Yddk= =mTyc -----END PGP SIGNATURE-----