[Jifty-commit] r1200 - in jifty/trunk: . lib/Jifty lib/Jifty/Script t/Continuations/bin t/Mapper/bin

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Thu Jun 8 00:02:03 EDT 2006


Author: clkao
Date: Thu Jun  8 00:01:57 2006
New Revision: 1200

Added:
   jifty/trunk/lib/Jifty/TestServer.pm   (contents, props changed)
   jifty/trunk/t/Continuations/bin/jifty
      - copied, changed from r1187, /jifty/trunk/bin/jifty
   jifty/trunk/t/Mapper/bin/jifty
      - copied, changed from r1187, /jifty/trunk/bin/jifty
   jifty/trunk/t/TestApp/bin/jifty
      - copied, changed from r1187, /jifty/trunk/bin/jifty
Modified:
   jifty/trunk/Makefile.PL
   jifty/trunk/lib/Jifty/Script/Server.pm
   jifty/trunk/lib/Jifty/Server.pm
   jifty/trunk/lib/Jifty/Test.pm
   jifty/trunk/lib/Jifty/Web.pm

Log:
New testing environment that invokes standalone 'jifty server' rather
than using Test::HTTP::Server::Simple.  This allows us to use
Devel::DProf and Devel::Cover.


Modified: jifty/trunk/Makefile.PL
==============================================================================
--- jifty/trunk/Makefile.PL	(original)
+++ jifty/trunk/Makefile.PL	Thu Jun  8 00:01:57 2006
@@ -47,7 +47,6 @@
 requires('String::Koremutake');
 requires('Test::Base' => 0.44);            # Test::Base::Filter
 requires('Test::HTML::Lint');
-requires('Test::HTTP::Server::Simple' => 0.02);
 requires('Test::More' => 0.62);
 requires('Test::Pod::Coverage');
 requires('Test::WWW::Mechanize');

Modified: jifty/trunk/lib/Jifty/Script/Server.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Script/Server.pm	(original)
+++ jifty/trunk/lib/Jifty/Script/Server.pm	Thu Jun  8 00:01:57 2006
@@ -31,9 +31,11 @@
 
 sub options {
     (
-     'p|port=s' => 'port',
-     'start'    => 'start',
-     'stop'     => 'stop',
+     'p|port=s'   => 'port',
+     'stop'       => 'stop',
+     'sigready=s' => 'sigready',
+     'quiet'      => 'quiet',
+     'dbiprof'    => 'dbiprof',
     )
 }
 
@@ -44,6 +46,11 @@
 
 =cut
 
+# XXX: if test::builder is not used, sometimes connection is not
+# properly closed, causing the client to wait for the content for a
+# 302 redirect, see t/06-signup.t, which timeouts after test 24.
+use Test::Builder ();
+
 sub run {
     my $self = shift;
     Jifty->new();
@@ -51,7 +58,7 @@
     if ($self->{stop}) {
         open my $fh, '<', PIDFILE;
         my $pid = <$fh>;
-        kill 'TERM', $pid;
+        kill 'TERM' => $pid;
         return;
     }
 
@@ -61,15 +68,21 @@
         File::Path::rmtree(["$data_dir/cache", "$data_dir/obj"]);
     }
 
-    if ($self->{start}) {
-        if (fork()) {
-            return;
-        }
-    }
+    $SIG{TERM} = sub { exit };
     open my $fh, '>', PIDFILE or die $!;
     print $fh $$;
     close $fh;
 
+    Jifty->new();
+
+    Jifty->handle->dbh->{Profile} = '6/DBI::ProfileDumper'
+        if $self->{dbiprof};
+
+    $ENV{JIFTY_SERVER_SIGREADY} ||= $self->{sigready}
+        if $self->{sigready};
+    Log::Log4perl->get_logger("Jifty::Server")->less_logging(3)
+        if $self->{quiet};
+
     Jifty::Server->new(port => $self->{port})->run;
 }
 

Modified: jifty/trunk/lib/Jifty/Server.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Server.pm	(original)
+++ jifty/trunk/lib/Jifty/Server.pm	Thu Jun  8 00:01:57 2006
@@ -124,7 +124,21 @@
     my $class = shift;
     our @ISA;
     unshift @ISA, "HTTP::Server::Simple::Recorder" unless $class->isa('HTTP::Server::Simple::Recorder');
-} 
+}
+
+=head2 after_setup_listener
+
+If C<$ENV{JIFTY_SERVER_SIGREADY}> is set, send the signal to the
+parent when the server is ready for requests.
+
+=cut
+
+sub after_setup_listener {
+    my $self = shift;
+    my $sig = $ENV{JIFTY_SERVER_SIGREADY} or return;
+    kill $sig => getppid();
+}
+
 
 1;
 

Modified: jifty/trunk/lib/Jifty/Test.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Test.pm	(original)
+++ jifty/trunk/lib/Jifty/Test.pm	Thu Jun  8 00:01:57 2006
@@ -98,18 +98,21 @@
 
 =head2 make_server
 
-Creates a new L<Jifty::Server> which C<ISA>
-L<Test::HTTP::Server::Simple> and returns it.
+Creates a new L<Jifty::Server> which C<ISA> L<Jifty::TestServer> and
+returns it.
 
 =cut
 
 sub make_server {
     my $class = shift;
 
-    require Test::HTTP::Server::Simple;
-    unshift @Jifty::Server::ISA, 'Test::HTTP::Server::Simple';
+    # XXX: Jifty::TestServer is not a Jifty::Server, it is actually
+    # server controller that invokes bin/jifty server. kill the
+    # unshift here once we fix all the tests expecting it to be
+    # jifty::server.
+    require Jifty::TestServer;
+    unshift @Jifty::Server::ISA, 'Jifty::TestServer';
 
-    Log::Log4perl->get_logger("Jifty::Server")->less_logging(3);
     my $server = Jifty::Server->new;
 
     return $server;

Added: jifty/trunk/lib/Jifty/TestServer.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/TestServer.pm	Thu Jun  8 00:01:57 2006
@@ -0,0 +1,70 @@
+package Jifty::TestServer;
+
+use strict;
+use warnings;
+use Cwd 'abs_path';
+use Test::Builder;
+my $Tester = Test::Builder->new;
+
+my $INC = [map { abs_path($_) } @INC ];
+my @perl = ($^X, map { "-I$_" } @$INC);
+
+=head1 NAME
+
+Jifty::TestServer - Starting and stopping jifty 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;
+
+    if (my $pid = fork()) {
+        # We are expecting a USR1 from the child Jifty::Server
+        # after it's ready to listen.
+        $SIG{USR1} = sub { };
+        sleep 15;
+        $self->{started} = 1;
+        $Tester->ok(1, $text);
+        # XXX: pull from jifty::config maybe
+        return "http://localhost:".$self->port;
+    }
+
+    require POSIX;
+    if ( $^O !~ /MSWin32/ ) {
+        POSIX::setsid()
+            or die "Can't start a new session: $!";
+    }
+
+    my @extra;
+    if (my $profile_file = $ENV{JIFTY_TESTSERVER_PROFILE}) {
+        push @extra, '-d:DProf';
+        $ENV{"PERL_DPROF_OUT_FILE_NAME"} = $profile_file;
+    }
+    if (my $coverage = $ENV{JIFTY_TESTSERVER_COVERAGE}) {
+        push @extra, '-MDevel::Cover';
+    }
+    # FIXME: put something here to ensure bin/jifty (even
+    # $findbin/../bin/jifty) exists
+    exec(@perl, @extra, 'bin/jifty', 'server', '--quiet',
+         '--sigready', 'USR1',
+         $ENV{JIFTY_TESTSERVER_DBIPROF} ? ('--dbiprof') : (),
+         );
+}
+
+sub DESTROY {
+    return unless $_[0]->{started};
+    exec(@perl, 'bin/jifty', 'server', '--stop');
+}
+
+1;

Modified: jifty/trunk/lib/Jifty/Web.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web.pm	(original)
+++ jifty/trunk/lib/Jifty/Web.pm	Thu Jun  8 00:01:57 2006
@@ -558,6 +558,8 @@
 
     # Abort or last_rule out of here
     $self->mason->abort if $self->mason;
+    print ".\r\n" unless $self->mason;
+#    close STDOUT unless $self->mason;
     Jifty::Dispatcher::last_rule();
 
 }

Copied: jifty/trunk/t/Continuations/bin/jifty (from r1187, /jifty/trunk/bin/jifty)
==============================================================================

Copied: jifty/trunk/t/Mapper/bin/jifty (from r1187, /jifty/trunk/bin/jifty)
==============================================================================

Copied: jifty/trunk/t/TestApp/bin/jifty (from r1187, /jifty/trunk/bin/jifty)
==============================================================================


More information about the Jifty-commit mailing list