Changeset 13791 for trunk/UnitTestContrib/test/unit/CacheTests.pm
- Timestamp:
- 01/23/12 06:00:05 (4 months ago)
- File:
-
- 1 edited
-
trunk/UnitTestContrib/test/unit/CacheTests.pm (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/UnitTestContrib/test/unit/CacheTests.pm
r13730 r13791 1 1 package CacheTests; 2 use strict; 3 use warnings; 2 4 3 use FoswikiFnTestCase ;5 use FoswikiFnTestCase(); 4 6 our @ISA = qw( FoswikiFnTestCase ); 5 7 6 use strict; 7 use Foswiki; 8 use Foswiki::Meta; 8 use Foswiki(); 9 use Foswiki::Meta(); 10 use File::Spec(); 11 use Foswiki::OopsException(); 12 use Foswiki::PageCache(); 9 13 use Error qw( :try ); 10 use Foswiki::OopsException;11 use Foswiki::PageCache;12 14 use Benchmark qw(:hireswallclock); 13 15 … … 17 19 my $this = shift; 18 20 my @page; 21 19 22 foreach my $dir (@INC) { 20 if ( opendir( D, "$dir/Foswiki/Cache" ) ) { 21 foreach my $alg ( readdir D ) { 23 if ( opendir( my $D, File::Spec->catdir( $dir, 'Foswiki', 'Cache' ) ) ) 24 { 25 foreach my $alg ( readdir $D ) { 22 26 next unless $alg =~ s/^(.*)\.pm$/$1/; 23 next if defined & $alg;27 next if defined &{$alg}; 24 28 $ENV{PATH} =~ /^(.*)$/ms; 25 $ENV{PATH} = $1;29 local $ENV{PATH} = $1; 26 30 ($alg) = $alg =~ /^(.*)$/ms; 27 eval "require Foswiki::Cache::$alg"; 28 if ($@) { 29 print STDERR 30 "Cannot test Foswiki::Cache::$alg\nCompilation error when trying to 'require' it\n"; 31 } 32 else { 31 32 if ( eval "require Foswiki::Cache::$alg; 1;" ) { 33 33 no strict 'refs'; 34 * $alg= sub {34 *{$alg} = sub { 35 35 my $this = shift; 36 36 $Foswiki::cfg{CacheManager} = 'Foswiki::Cache::' . $alg; … … 39 39 push( @page, $alg ); 40 40 } 41 else { 42 print STDERR 43 "Cannot test Foswiki::Cache::$alg\nCompilation error when trying to 'require' it\n"; 44 } 41 45 } 42 closedir( D);46 closedir($D); 43 47 } 44 48 } … … 50 54 sub DBFileMeta { 51 55 $Foswiki::cfg{MetaCacheManager} = 'Foswiki::Cache::DB_File'; 56 57 return; 52 58 } 53 59 54 60 sub BDBMeta { 55 61 $Foswiki::cfg{MetaCacheManager} = 'Foswiki::Cache::BDB'; 62 63 return; 56 64 } 57 65 … … 59 67 $Foswiki::cfg{HttpCompress} = 1; 60 68 $Foswiki::cfg{Cache}{Compress} = 1; 69 70 return; 61 71 } 62 72 … … 64 74 $Foswiki::cfg{HttpCompress} = 0; 65 75 $Foswiki::cfg{Cache}{Compress} = 0; 76 77 return; 66 78 } 67 79 … … 90 102 $Foswiki::cfg{Cache}{Compress} = 0; 91 103 $UI_FN ||= $this->getUIFn('view'); 92 }93 104 94 sub tear_down { 95 my $this = shift; 96 $this->SUPER::tear_down(); 105 return; 97 106 } 98 107 … … 102 111 $UI_FN ||= $this->getUIFn('view'); 103 112 104 my $query = new Unit::Request( { skin => ['none'], } );113 my $query = Unit::Request->new( { skin => ['none'], } ); 105 114 $query->path_info("/"); 106 115 $query->method('POST'); 107 116 108 my $fatwilly = new Foswiki( $this->{test_user_login}, $query );117 $this->createNewFoswikiSession( $this->{test_user_login}, $query ); 109 118 110 119 # This first request should *not* be satisfied from the cache, but 111 120 # the cache should be populated with the result. 112 my $p1start = new Benchmark();121 my $p1start = Benchmark->new(); 113 122 my ($one) = $this->capture( 114 123 sub { 115 124 no strict 'refs'; 116 & $UI_FN($fatwilly);125 &{$UI_FN}( $this->{session} ); 117 126 use strict 'refs'; 118 $Foswiki::engine->finalize( $ fatwilly->{response},119 $ fatwilly->{request} );127 $Foswiki::engine->finalize( $this->{session}{response}, 128 $this->{session}{request} ); 120 129 } 121 130 ); 122 131 123 my $p1end = new Benchmark();132 my $p1end = Benchmark->new(); 124 133 print STDERR "R1 " . timestr( timediff( $p1end, $p1start ) ) . "\n"; 125 $fatwilly->finish();126 134 127 $ fatwilly = new Foswiki( $this->{test_user_login}, $query );135 $this->createNewFoswikiSession( $this->{test_user_login}, $query ); 128 136 129 137 # This second request should be satisfied from the cache 130 my $p2start = new Benchmark();138 my $p2start = Benchmark->new(); 131 139 my ($two) = $this->capture( 132 140 sub { 133 141 no strict 'refs'; 134 & $UI_FN($fatwilly);142 &{$UI_FN}( $this->{session} ); 135 143 use strict 'refs'; 136 $Foswiki::engine->finalize( $ fatwilly->{response},137 $ fatwilly->{request} );144 $Foswiki::engine->finalize( $this->{session}{response}, 145 $this->{session}{request} ); 138 146 } 139 147 ); 140 my $p2end = new Benchmark();148 my $p2end = Benchmark->new(); 141 149 print STDERR "R2 " . timestr( timediff( $p2end, $p2start ) ) . "\n"; 142 $fatwilly->finish();143 150 144 151 # Massage the HTML for comparison … … 164 171 165 172 $this->assert_html_equals( $one, $two ); 173 174 return; 166 175 } 167 176
Note: See TracChangeset
for help on using the changeset viewer.
