CHI/t/Driver/Memory.pm

filter: Statementstmt 92.0% 81 / 88 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 23 / 23 Podpod 0.0% 0 / 9 totaltotal 86.2% 107 / 124 SCAR 16.1
CC
5
Cov
91%
test_lru_discard
6.5
new_cache
2.0
test_clear_datastore
2.0
CRAP 5.0
« CHI/Driver/Memory.pm ↑ Summary CHI/t/Driver/RawMemory.pm »
1 package CHI::t::Driver::Memory;
2 3 $CHI::t::Driver::Memory::VERSION = '0.59';
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use CHI::Test;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use CHI::Test::Driver::Role::CheckKeyValidity;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Test::Warn;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use base qw(CHI::t::Driver);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Skip multiple process test
11 ▶sub test_multiple_processes { }
Subroutine test_multiple_processes: called CC=1 SCAR=0.0
Pod undocumented
12  
13 sub new_cache_options {
14 276 ▶ my $self = shift;
Subroutine new_cache_options: called CC=1 SCAR=0.0
Pod undocumented
15  
16 276 return ( $self->SUPER::new_cache_options(), global => 1 );
17 }
18  
19 sub new_cache {
20 182 ▶ my $self = shift;
Subroutine new_cache: called CC=2 SCAR=6.9
Pod undocumented
21  
22 182 my %params = ( $self->new_cache_options(), @_ );
23  
24 # If new_cache called with datastore, ignore global flag (otherwise would be an error)
25 #
26 182 ▶ if ( $params{datastore} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"datastore"}) 6 176 182
27 6 delete $params{global};
28 }
29  
30 # Check test key validity on every get and set - only necessary to do for one driver
31 #
32 182 $params{roles} = ['+CHI::Test::Driver::Role::CheckKeyValidity'];
33 182 $params{test_object} = $self;
34  
35 182 my $cache = CHI->new(%params);
36 182 return $cache;
37 }
38  
39 sub test_short_driver_name : Tests {
40 1 ▶ my ($self) = @_;
Subroutine test_short_driver_name: called CC=1 SCAR=0.0
Pod undocumented
41  
42 1 my $cache = $self->{cache};
43 1 is( $cache->short_driver_name, 'Memory' );
44 3 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 # Warn if global or datastore not passed, but still use global datastore by default
47 #
48 sub test_global_or_datastore_required : Tests {
49 3 ▶ my ( $cache, $cache2 );
Subroutine test_global_or_datastore_required: called CC=1 SCAR=0.0
Pod undocumented
50 3 ▶ warning_like( sub { $cache = CHI->new( driver => 'Memory' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
51 3 qr/must specify either/ );
52 3 ▶ warning_like( sub { $cache2 = CHI->new( driver => 'Memory' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
53 3 qr/must specify either/ );
54 3 $cache->set( 'foo', 5 );
55 3 is( $cache2->get('foo'), 5, "defaulted to global datastore" );
56 3 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
57  
58 # Make sure two caches don't share datastore
59 #
60 sub test_different_datastores : Tests {
61 3 ▶ my $self = shift;
Subroutine test_different_datastores: called CC=1 SCAR=0.0
Pod undocumented
62 3 my $cache1 = CHI->new( driver => 'Memory', datastore => {} );
63 3 my $cache2 = CHI->new( driver => 'Memory', datastore => {} );
64 3 $self->set_some_keys($cache1);
65 3 ok( !$cache2->get_keys() );
66 3 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
67  
68 # Make sure two global=0 caches don't share datastore
69 #
70 sub test_different_global_0 : Tests {
71 3 ▶ my $self = shift;
Subroutine test_different_global_0: called CC=1 SCAR=0.0
Pod undocumented
72 3 my $cache1 = CHI->new( driver => 'Memory', global => 0 );
73 3 my $cache2 = CHI->new( driver => 'Memory', global => 0 );
74 3 $self->set_some_keys($cache1);
75 3 ok( !$cache2->get_keys() );
76 3 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78 # Make sure cache is cleared when datastore itself is cleared
79 #
80 sub test_clear_datastore : Tests {
81 3 ▶ my $self = shift;
Subroutine test_clear_datastore: called CC=2 SCAR=6.9
Pod undocumented
82 3 $self->num_tests( $self->{key_count} * 3 + 6 );
83  
84 3 my (@caches);
85  
86 my %datastore;
87 3 $caches[0] =
88 $self->new_cache( namespace => 'name', datastore => \%datastore );
89 3 $caches[1] =
90 $self->new_cache( namespace => 'other', datastore => \%datastore );
91 3 $caches[2] =
92 $self->new_cache( namespace => 'name', datastore => \%datastore );
93 3 $self->set_some_keys( $caches[0] );
94 3 $self->set_some_keys( $caches[1] );
95 3 %datastore = ();
96  
97 3 foreach my $i ( 0 .. 2 ) {
98 9 $self->_verify_cache_is_cleared( $caches[$i],
99 "cache $i after out of scope" );
100 }
101 3 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
102  
103 sub test_lru_discard : Tests {
104 2 ▶ my $self = shift;
Subroutine test_lru_discard: called CC=3 SCAR=18.7
Pod undocumented
105 2 ▶ return 'author testing only' unless ( $ENV{AUTHOR_TESTING} );
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"AUTHOR_TESTING"} 2 0 2
106  
107 0 my $cache = $self->new_cleared_cache( max_size => 41 );
108 0 is( $cache->discard_policy, 'lru' );
109 0 my $value_20 = 'x' x 6;
110 0 foreach my $key ( map { "key$_" } (qw(1 2 3 4 5 6 5 6 5 3 2)) ) {
111 0 $cache->set( $key, $value_20 );
112 }
113 0 cmp_set( [ $cache->get_keys ], [ "key2", "key3" ] );
114 3 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
115  
116 3 1;
« CHI/Driver/Memory.pm ↑ Summary CHI/t/Driver/RawMemory.pm »