[Catalyst-commits] r13692 - in trunk/Catalyst-Plugin-PageCache: . t t/lib/TestApp/Controller

timbunce at dev.catalyst.perl.org timbunce at dev.catalyst.perl.org
Tue Nov 9 18:49:01 GMT 2010


Author: timbunce
Date: 2010-11-09 18:49:01 +0000 (Tue, 09 Nov 2010)
New Revision: 13692

Modified:
   trunk/Catalyst-Plugin-PageCache/Changes
   trunk/Catalyst-Plugin-PageCache/t/15busy_lock.t
   trunk/Catalyst-Plugin-PageCache/t/lib/TestApp/Controller/Cache.pm
Log:
Made t/15busy_lock.t test more robust

Modified: trunk/Catalyst-Plugin-PageCache/Changes
===================================================================
--- trunk/Catalyst-Plugin-PageCache/Changes	2010-11-09 17:53:49 UTC (rev 13691)
+++ trunk/Catalyst-Plugin-PageCache/Changes	2010-11-09 18:49:01 UTC (rev 13692)
@@ -1,9 +1,10 @@
 Revision history for Perl extension Catalyst::Plugin::PageCache
 
-0.31    2010-11-05
+0.31    2010-11-09
         - Fixed config in test apps to silence warnings from tests.
         - Fixed module version number.
         - Require File::Path 2.07.
+        - Made t/15busy_lock.t test more robust
 
 0.30    2010-11-03 16:03  r13688
         - Updated tests to use Cache::FileCache instead of the deprecated ::FileCache.

Modified: trunk/Catalyst-Plugin-PageCache/t/15busy_lock.t
===================================================================
--- trunk/Catalyst-Plugin-PageCache/t/15busy_lock.t	2010-11-09 17:53:49 UTC (rev 13691)
+++ trunk/Catalyst-Plugin-PageCache/t/15busy_lock.t	2010-11-09 18:49:01 UTC (rev 13692)
@@ -9,26 +9,26 @@
 use File::Path;
 use Time::HiRes qw(time sleep);
 
-BEGIN {
-    eval "use Catalyst::Plugin::Cache";
-    if ( $@ ) {
-        plan skip_all => 'needs Catalyst::Plugin::Cache for testing';
-    }
-}
+plan skip_all => "needs Catalyst::Plugin::Cache for testing: $@"
+    if not eval "use Catalyst::Plugin::Cache; 1";
 
-plan $^O =~ /Win32/
-    ? ( skip_all => 'Cannot run this test on Windows' )
-    : ( tests => 4 );
+plan skip_all => 'Cannot run this test on Windows' # XXX still true?
+    if $^O =~ /Win32/;
 
+plan tests => 7;
+
 use Catalyst::Test 'TestApp';
 
 TestApp->config->{'Plugin::PageCache'}->{busy_lock} = 5;
 
+ok( request('http://host1/cache/set_count/0', 'request ok' ) );
 # Request a slow page once, to cache it
 ok( my $res = request('http://localhost/cache/busy'), 'request ok' );
+is( $res->content, 1, 'count is 1' );
 
-# Wait for it to expire
-sleep 1;
+sleep 1; # delay so cached page will have expired
+my $cache_time = time + 1;
+1 while time < $cache_time; # spin till clock ticks to make test more robust
 
 # Fork, parent requests slow page.  After parent requests, child
 # requests, and gets cached page while parent is rebuilding cache
@@ -37,21 +37,32 @@
     my $start = time();
     ok( $res = request('http://localhost/cache/busy'), 'parent request ok' );
     cmp_ok( time() - $start, '>=', 1, 'slow parent response ok' );
+    is( $res->content, 2, 'parent generated new response' );
     
     # Get status from child, since it can't print 'ok' messages without
     # confusing Test::More
     wait;
-    is( $? >> 8, 0, 'fast child response ok' );
+    is( $? >> 8, 0, "fast child response ($?)" );
 }
 else {
     # child
-    sleep 0.1;
+    sleep 1; # delay to ensure parent makes request first
+    # but not long enough for the parent to have finished
     my $start = time();
-    request('http://localhost/cache/busy');
-    if ( time() - $start < 1 ) {
-        exit 0;
+    $res = request('http://localhost/cache/busy');
+    my $dur = time() - $start;
+
+    my $errors = 0;
+
+    my $content = $res->content;
+    if ($content ne '1') {
+        warn "Child didn't get cached response ($content)\n";
+        ++$errors;
     }
-    else {
-        exit 1;
+    if ($dur >= 1) {
+        warn "Child got response slowly ($dur)\n";
+        ++$errors;
     }
+
+    exit $errors;
 }

Modified: trunk/Catalyst-Plugin-PageCache/t/lib/TestApp/Controller/Cache.pm
===================================================================
--- trunk/Catalyst-Plugin-PageCache/t/lib/TestApp/Controller/Cache.pm	2010-11-09 17:53:49 UTC (rev 13691)
+++ trunk/Catalyst-Plugin-PageCache/t/lib/TestApp/Controller/Cache.pm	2010-11-09 18:49:01 UTC (rev 13692)
@@ -103,9 +103,9 @@
 
     $c->cache_page( 1 );
 
-    sleep 1;
+    sleep 2;
 
-    $c->res->body('busy');
+    $c->res->output( $c->config->{counter} );
 }
 
 sub get_key : Local {




More information about the Catalyst-commits mailing list