line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CHI::t::SetError; |
2
|
|
|
|
|
|
|
$CHI::t::SetError::VERSION = '0.59'; |
3
|
1
|
|
|
1
|
|
312
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
5
|
1
|
|
|
1
|
|
341
|
use CHI::Test; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use CHI::Test::Util qw(activate_test_logger); |
7
|
|
|
|
|
|
|
use base qw(CHI::Test::Class); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub readonly_cache { |
10
|
|
|
|
|
|
|
my ($on_set_error) = @_; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
return CHI->new( |
13
|
|
|
|
|
|
|
driver => '+CHI::Test::Driver::Readonly', |
14
|
|
|
|
|
|
|
on_set_error => $on_set_error, |
15
|
|
|
|
|
|
|
global => 1 |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub test_set_errors : Tests { |
20
|
|
|
|
|
|
|
my ( $key, $value ) = ( 'medium', 'medium' ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $error_pattern = |
23
|
|
|
|
|
|
|
qr/error during cache set for namespace='.*', key='medium', size=\d+.*: read-only cache/; |
24
|
|
|
|
|
|
|
my $log = activate_test_logger(); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $cache; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$cache = readonly_cache('ignore'); |
29
|
|
|
|
|
|
|
lives_ok( sub { $cache->set( $key, $value ) }, "ignore - lives" ); |
30
|
|
|
|
|
|
|
ok( !defined( $cache->get($key) ), "ignore - miss" ); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$cache = readonly_cache('die'); |
33
|
|
|
|
|
|
|
throws_ok( sub { $cache->set( $key, $value ) }, |
34
|
|
|
|
|
|
|
$error_pattern, "die - dies" ); |
35
|
|
|
|
|
|
|
ok( !defined( $cache->get($key) ), "die - miss" ); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$log->clear(); |
38
|
|
|
|
|
|
|
$cache = readonly_cache('log'); |
39
|
|
|
|
|
|
|
lives_ok( sub { $cache->set( $key, $value ) }, "log - lives" ); |
40
|
|
|
|
|
|
|
ok( !defined( $cache->get($key) ), "log - miss" ); |
41
|
|
|
|
|
|
|
$log->contains_ok(qr/cache get for .* key='medium', .*: MISS/); |
42
|
|
|
|
|
|
|
$log->contains_ok($error_pattern); |
43
|
|
|
|
|
|
|
$log->empty_ok(); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my ( $err_msg, $err_key ); |
46
|
|
|
|
|
|
|
$cache = readonly_cache( |
47
|
|
|
|
|
|
|
sub { |
48
|
|
|
|
|
|
|
( $err_msg, $err_key ) = @_; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
lives_ok( sub { $cache->set( $key, $value ) }, "custom - lives" ); |
52
|
|
|
|
|
|
|
ok( !defined( $cache->get($key) ), "custom - miss" ); |
53
|
|
|
|
|
|
|
like( $err_msg, $error_pattern, "custom - got msg" ); |
54
|
|
|
|
|
|
|
is( $err_key, $key, "custom - got key" ); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
throws_ok( |
57
|
|
|
|
|
|
|
sub { readonly_cache('bad') }, |
58
|
|
|
|
|
|
|
qr/Validation failed for|isa check for ".*" failed/, |
59
|
|
|
|
|
|
|
"bad - dies" |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |