[Catalyst-commits] r8495 - in trunk/Catalyst-Plugin-PageCache: . t t/lib/TestApp/C

andyg at dev.catalyst.perl.org andyg at dev.catalyst.perl.org
Thu Oct 2 05:08:42 BST 2008


Author: andyg
Date: 2008-10-02 05:08:42 +0100 (Thu, 02 Oct 2008)
New Revision: 8495

Added:
   trunk/Catalyst-Plugin-PageCache/t/15busy_lock.t
Removed:
   trunk/Catalyst-Plugin-PageCache/TODO
Modified:
   trunk/Catalyst-Plugin-PageCache/t/lib/TestApp/C/Cache.pm
Log:
Added a test for busy_lock

Deleted: trunk/Catalyst-Plugin-PageCache/TODO
===================================================================
--- trunk/Catalyst-Plugin-PageCache/TODO	2008-10-01 19:25:32 UTC (rev 8494)
+++ trunk/Catalyst-Plugin-PageCache/TODO	2008-10-02 04:08:42 UTC (rev 8495)
@@ -1 +0,0 @@
-- disable index stuff by default, make regex clear_cached_page an option

Added: trunk/Catalyst-Plugin-PageCache/t/15busy_lock.t
===================================================================
--- trunk/Catalyst-Plugin-PageCache/t/15busy_lock.t	                        (rev 0)
+++ trunk/Catalyst-Plugin-PageCache/t/15busy_lock.t	2008-10-02 04:08:42 UTC (rev 8495)
@@ -0,0 +1,53 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+use Test::More;
+use File::Path;
+use Time::HiRes qw(time sleep);
+
+plan $^O =~ /Win32/
+    ? ( skip_all => 'Cannot run this test on Windows' )
+    : ( tests => 4 );
+
+# remove previous cache
+rmtree 't/var' if -d 't/var';
+
+use Catalyst::Test 'TestApp';
+
+TestApp->config->{'Plugin::PageCache'}->{busy_lock} = 5;
+
+# Request a slow page once, to cache it
+ok( my $res = request('http://localhost/cache/busy'), 'request ok' );
+
+# Wait for it to expire
+sleep 1;
+
+# Fork, parent requests slow page.  After parent requests, child
+# requests, and gets cached page while parent is rebuilding cache
+if ( my $pid = fork ) {
+    # parent
+    my $start = time();
+    ok( $res = request('http://localhost/cache/busy'), 'parent request ok' );
+    cmp_ok( time() - $start, '>=', 1, 'slow parent response ok' );
+    
+    # Get status from child, since it can't print 'ok' messages without
+    # confusing Test::More
+    wait;
+    is( $? >> 8, 0, 'fast child response ok' );
+}
+else {
+    # child
+    sleep 0.1;
+    my $start = time();
+    request('http://localhost/cache/busy');
+    if ( time() - $start < 1 ) {
+        exit 0;
+    }
+    else {
+        exit 1;
+    }
+}
\ No newline at end of file


Property changes on: trunk/Catalyst-Plugin-PageCache/t/15busy_lock.t
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: trunk/Catalyst-Plugin-PageCache/t/lib/TestApp/C/Cache.pm
===================================================================
--- trunk/Catalyst-Plugin-PageCache/t/lib/TestApp/C/Cache.pm	2008-10-01 19:25:32 UTC (rev 8494)
+++ trunk/Catalyst-Plugin-PageCache/t/lib/TestApp/C/Cache.pm	2008-10-02 04:08:42 UTC (rev 8495)
@@ -90,4 +90,14 @@
     $c->res->output( $c->config->{counter} );
 }
 
+sub busy : Local {
+    my ( $self, $c ) = @_;
+    
+    $c->cache_page( 1 );
+    
+    sleep 1;
+    
+    $c->res->body('busy');
+}
+
 1;




More information about the Catalyst-commits mailing list