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