[Jifty-commit] r5174 - in jifty/trunk: lib/Jifty lib/Jifty/TestServer
Jifty commits
jifty-commit at lists.jifty.org
Thu Feb 28 20:18:38 EST 2008
Author: alexmv
Date: Thu Feb 28 20:18:33 2008
New Revision: 5174
Added:
jifty/trunk/lib/Jifty/TestServer/
jifty/trunk/lib/Jifty/TestServer/Apache.pm
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Test.pm
Log:
r28188 at zoq-fot-pik: chmrr | 2008-02-28 20:17:25 -0500
* Run tests against an apache httpd
Modified: jifty/trunk/lib/Jifty/Test.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Test.pm (original)
+++ jifty/trunk/lib/Jifty/Test.pm Thu Feb 28 20:18:33 2008
@@ -421,6 +421,9 @@
$^O eq 'MSWin32') {
require Jifty::TestServer;
unshift @Jifty::Server::ISA, 'Jifty::TestServer';
+ } elsif ($ENV{JIFTY_APACHETEST}) {
+ require Jifty::TestServer::Apache;
+ unshift @Jifty::Server::ISA, 'Jifty::TestServer::Apache';
}
else {
require Test::HTTP::Server::Simple;
@@ -430,7 +433,7 @@
my $server = Jifty::Server->new;
return $server;
-}
+}
=head2 web
Added: jifty/trunk/lib/Jifty/TestServer/Apache.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/TestServer/Apache.pm Thu Feb 28 20:18:33 2008
@@ -0,0 +1,98 @@
+package Jifty::TestServer::Apache;
+
+use strict;
+use warnings;
+use File::Slurp;
+use File::Spec;
+use Test::Builder;
+my $Tester = Test::Builder->new;
+
+# explicitly ignore ClassLoader objects in @INC,
+# which'd be ignored in the end, though.
+my $INC = [grep { defined } map { File::Spec->rel2abs($_) } grep { !ref } @INC ];
+
+=head1 NAME
+
+Jifty::TestServer::Apache - Starting and stopping an apache server for tests
+
+=head1 DESCRIPTION
+
+=head1 METHOD
+
+=head2 started_ok
+
+Like started_ok in C<Test::HTTP::Server::Simple>, start the server and
+return the URL.
+
+=cut
+
+sub started_ok {
+ my $self = shift;
+ my $text = shift;
+ $text = 'started server' unless defined $text;
+
+ $self->{pidfile} = File::Temp->new;
+ close $self->{pidfile};
+ $self->{pidfile} .= "";
+ my $ipc = File::Temp::tempdir( CLEANUP => 1 );
+ my $errorlog = File::Temp->new;
+ my $config = File::Temp->new;
+
+ my $PATH = Jifty::Util->absolute_path("bin/jifty");
+ my $STATIC = Jifty::Util->absolute_path(Jifty->config->framework('Web')->{StaticRoot});
+
+ print $config <<"CONFIG";
+ServerName 127.0.0.1
+Port @{[$self->port]}
+User @{[scalar getpwuid($<)]}
+Group @{[scalar getgrgid($()]}
+MinSpareServers 1
+StartServers 1
+PidFile @{[$self->{pidfile}]}
+ErrorLog $errorlog
+<Location />
+ Options FollowSymLinks ExecCGI
+</Location>
+FastCgiIpcDir $ipc
+FastCgiServer $PATH -initial-env JIFTY_COMMAND=fastcgi -idle-timeout 300 -processes 1 -initial-env PERL5LIB=@{[join(":",@{$INC})]}
+ScriptAlias / $PATH/
+Alias /static/ $STATIC/
+CONFIG
+ close $config;
+
+ if (fork()) {
+ my $pid;
+ for (1..15) {
+ last if $pid = $self->pids;
+ sleep 1;
+ }
+ if ($pid) {
+ $self->{started} = 1;
+ $Tester->ok(1, $text);
+ return "http://localhost:".$self->port;
+ } else {
+ $Tester->ok(0, $text);
+ return "";
+ }
+ }
+
+ exec($ENV{JIFTY_APACHETEST}, "-f", $config);
+}
+
+sub pids {
+ my $self = shift;
+ return unless -e $self->{pidfile};
+ my $pid = read_file($self->{pidfile});
+ chomp $pid;
+ return ($pid);
+}
+
+sub DESTROY {
+ return unless $_[0]->{started};
+ my($pid) = $_[0]->pids;
+ kill(15, $pid) if $pid;
+ 1 while ($_ = wait()) >= 0;
+ sleep 1 while kill(0, $pid);
+}
+
+1;
More information about the Jifty-commit
mailing list