File Coverage

blib/lib/CHI/t/Driver/Subcache/l1_cache.pm
Criterion Covered Total %
statement 40 40 100.0
branch n/a
condition 2 3 66.6
subroutine 12 12 100.0
pod 0 5 0.0
total 54 60 90.0


line stmt bran cond sub pod time code
1             package CHI::t::Driver::Subcache::l1_cache;
2             $CHI::t::Driver::Subcache::l1_cache::VERSION = '0.61';
3 1     1   551 use strict;
  1         9  
  1         35  
4 1     1   6 use warnings;
  1         2  
  1         37  
5 1     1   410 use CHI::Test;
  1         3  
  1         8  
6 1     1   8 use CHI::Test::Util qw(activate_test_logger);
  1         2  
  1         52  
7 1     1   745 use File::Temp qw(tempdir);
  1         18254  
  1         61  
8 1     1   8 use base qw(CHI::t::Driver::Subcache);
  1         3  
  1         509  
9              
10             my $root_dir;
11              
12             sub testing_driver_class {
13 81     81 0 971 return 'CHI::Driver::File';
14             }
15              
16             sub new_cache_options {
17 81     81 0 220 my $self = shift;
18              
19 81   66     369 $root_dir ||=
20             tempdir( "chi-driver-subcache-l1-XXXX", TMPDIR => 1, CLEANUP => 1 );
21             return (
22 81         1060 $self->SUPER::new_cache_options(),
23             root_dir => $root_dir,
24             l1_cache => { driver => 'Memory', global => 1 },
25             );
26             }
27              
28             sub test_stats : Tests {
29 1     1 0 784 my $self = shift;
30              
31 1         6 my $stats = $self->testing_chi_root_class->stats;
32 1         8 $stats->enable();
33              
34 1         8 my ( $key, $value ) = $self->kvpair();
35 1         4 my $start_time = time();
36              
37 1         3 my $cache;
38 1         5 $cache = $self->new_cache( namespace => 'Foo' );
39 1         28 $cache->get($key);
40 1         26 $cache->set( $key, $value, 80 );
41 1         27 $cache->get($key);
42              
43 1         8 my $log = activate_test_logger();
44 1         7 $log->empty_ok();
45 1         445 $stats->flush();
46              
47 1         10 $log->contains_ok(
48             qr/CHI stats: \{"absent_misses":1,"end_time":\d+,"get_time_ms":\d+,"label":"File","namespace":"Foo","root_class":"CHI","set_key_size":6,"set_time_ms":\d+,"set_value_size":20,"sets":1,"start_time":\d+}/
49             );
50 1         384 $log->contains_ok(
51             qr/CHI stats: \{"absent_misses":1,"end_time":\d+,"get_time_ms":\d+,"hits":1,"label":"File:l1_cache","namespace":"Foo","root_class":"CHI","set_key_size":6,"set_time_ms":\d+,"set_value_size":20,"sets":1,"start_time":\d+}/
52             );
53              
54 1     1   8 }
  1         10  
  1         5  
55              
56             # not working yet
57       1 0   sub test_append { }
58              
59             # won't work in presence of l1 cache
60       1 0   sub test_max_key_length { }
61              
62             1;