Link/Tester/Adaptive.pm

filter: Statementstmt 88.4% 160 / 181 Branchbran 66.0% 66 / 100 Conditioncond 70.8% 17 / 24 MC/DCmcdc 42.8% 6 / 14 Subroutinesub 87.5% 21 / 24 Podpod 50.0% 2 / 4 totaltotal 78.3% 272 / 347 CC 61 SCAR 30.1
CC
61
Cov
80%
calculate_test_state
38.4
consider_test
25.6
time_want_test
12.0
CRAP 20.3
« Link/Reporter/LongList.pm ↑ Summary Link.pm »
1 package WWW::Link::Tester::Adaptive;
2 3 $REVISION=q$Revision: 1.12 $ ; $VERSION = sprintf ( "%d.%02d", $REVISION =~ /(\d+).(\d+)/ );
3  
4 =head1 NAME
5  
6 WWW::Link::Test - adaptive functions for testing links.
7  
8 =head1 SYNOPSIS
9  
10 use WWW::Link::Test
11 $ua=create_a_user_agent();
12 $link=get_a_link_object();
13 WWW::Link::Test::test_link($ua, $link);
14  
15 =head1 DESCRIPTION
16  
17 The adaptive tester uses either a simple or a complex tester depending
18 on which one has been working correctly.
19  
20 =cut
21  
22 # Only one method currently impemented. The others were done
23 # differently but may come back later..
24  
25 =head1 METHODS
26  
27 =head2 test_link
28  
29 This function tests a link by going out to the world and checking it
30 and then telling the associated link object what happened.
31  
32 =cut
33  
34 3 ▶use WWW::Link::Tester;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 3 ▶use WWW::Link::Tester::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 3 ▶use WWW::Link::Tester::Complex;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 3 @ISA=qw(WWW::Link::Tester);
39  
40 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 3 ▶use vars qw($mode);
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 3 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
45 3 my $proto = shift;
46 3 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
030
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
47 3 my $self = {};
48 3 my $ua=shift;
49 3 $self->{"complex"}=new WWW::Link::Tester::Complex $ua;
50 3 $self->{"simple"}=new WWW::Link::Tester::Simple $ua;
51 3 bless $self, $class;
52 }
53  
54 28 ▶sub test_link {
Subroutine test_link: called CC=3 SCAR=11.0
Pod documented
55 28 my $self=shift;
56 28 my $link=shift;
57 28 my $simple=undef;
58 28 my $verbose=$self->{"verbose"};
59  
60 28 my $cookie=$self->check_cookie($link);
61  
62 28 my $url=$link->url();
63  
64 28 my($mode, undef)=$cookie->calculate_test_state($link);
65  
66 28 my ($response, @redirects);
67 CASE: {
68 28 ▶ ($mode==WWW::Link::Tester::Adaptive::Cookie::MODE_SIMPLE() ) and do {
Branch: 1 branch
BranchTrueFalseTotal
$mode == WWW::Link::Tester::Adaptive::Cookie::MODE_SIMPLE() and do { () = $self->{"simple"}->get_response($link); last CASE } 22 6 28
69 22 ($response, @redirects) = $self->{"simple"}->get_response($link);
70 22 last CASE;
71 };
72 6 ▶ ($mode==WWW::Link::Tester::Adaptive::Cookie::MODE_COMPLEX() ) and do {
Branch: 1 branch
BranchTrueFalseTotal
$mode == WWW::Link::Tester::Adaptive::Cookie::MODE_COMPLEX() and do { () = $self->{"complex"}->get_response($link); last CASE } 6 0 6
73 6 ($response, @redirects) = $self->{"complex"}->get_response($link);
74 6 last CASE;
75 };
76 0 die "unknown testing mode $mode";
77 }
78  
79 28 $self->handle_response($link,$mode,$response,@redirects);
80  
81 28 return;
82 }
83  
84 =head2 handle_response
85  
86 The link tester has recieved a response, now the question is what do
87 we do with it. It depends on our testing mode.
88  
89 =cut
90  
91 29 ▶sub handle_response {
Subroutine handle_response: called CC=4 SCAR=13.9
Pod documented
92 29 my $self=shift;
93 29 my $link=shift;
94 29 my $mode=shift;
95 29 my $response=shift;
96 29 my @redirects=@_;
97  
98 29 my $cookie=$self->check_cookie($link);
99  
100 29 my $apply=$cookie->consider_test($link,$response,$mode);
101  
102  
103 29 ▶ if ( $apply ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($apply) { } 26 3 29
104 26 ▶ print STDERR "applying response\n" if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 26 26
105 26 $self->apply_response($link,$response,@redirects);
106 } else {
107 3 ▶ print STDERR "not applying response\n" if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 3 3
108 }
109  
110 29 $link->store_response($response, time, ref $self, $mode);
111 29 $link->test_cookie($cookie);
112 }
113  
114 =head1 check_cookie
115  
116 This verifies that the given link has a useful test cookie, and gives
117 it an appropriate one if it doesn't.
118  
119 =cut
120  
121 57 ▶sub check_cookie {
Subroutine check_cookie: called CC=4 SCAR=14.0
Pod undocumented
122 57 my $self=shift;
123 57 my $link=shift;
124 57 my $cookie=$link->test_cookie();
125  
126 CASE: {
127 57 ▶ defined $cookie && ref($cookie) =~ m/WWW::Link::Tester::Adaptive::Cookie/
Branch: 1 branch
BranchTrueFalseTotal
defined $cookie and ref($cookie) =~ /WWW::Link::Tester::Adaptive::Cookie/ and last 39 18 57
Condition66%2/3
defined $cookie and ref($cookie) =~ /WWW::Link::Tester::Adaptive::Cookie/
!ll&&!rl&&r
18039
MC/DC50%1/2
defined $cookie and ref($cookie) =~ /WWW::Link::Tester::Adaptive::Cookie/
defined $cookie ref($cookie) =~ /WWW::Link::Tester::Adaptive::Cookie/
Truth table66%2/3
A and B
A= defined $cookieB= ref($cookie) =~ /WWW::Link::Tester::Adaptive::Cookie/
ABresult
0X0
100
111
128 and last;
129 18 ▶ defined $cookie and warn "replacing old cookie type: " . ref $cookie;
Branch: 1 branch
BranchTrueFalseTotal
defined $cookie and warn 'replacing old cookie type: ' . ref($cookie) 0 18 18
130 18 $cookie=WWW::Link::Tester::Adaptive::Cookie->new();
131 }
132 57 return $cookie;
133 }
134  
135  
136 package WWW::Link::Tester::Adaptive::Cookie;
137  
138 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
139 3 ▶use WWW::Link::Tester;
Subroutine BEGIN: called CC=1 SCAR=0.0
140  
141 3 our ( $verbose );
142  
143 =head1 TESTING MODES
144  
145 We have two different ways of testing. One us network efficient, but
146 is less likely to give a fully correct answer. The other is less
147 network efficient, but more tests more carefully.
148  
149 We assume that the complex testing system is correct. We will allow
150 the simple testing system to be used only as long as we have no
151 reason to suspect inaccuracy we will test with the simple tester.
152  
153 =head2 verifying testing..
154  
155 Every now and then (after 20 tests) we will verify that our method of
156 testing is consistent. We do this by trying simple then complex
157 testing in order. If they are inconsistent then we finally try simple
158 testing one more time then mark the simple testing as wrong.
159  
160 =head2 testing at status changes.
161  
162 If a link changes status then we will try to verify it sooner..
163  
164 =head2 statuses
165  
166 There are two flags that can be set.
167  
168 OKAY_SIMPLE_WORKING - link tests correctly with both complex and
169 simple testers when it is working.
170  
171 OKAY_SIMPLE_BROKEN- link tests correctly with both complex and
172 simple testers when it is broken.
173  
174 As long as these are both set then most of our testing should be done
175 in simple mode.
176  
177 =cut
178  
179 # Occasionally we try complex mode. We see if this gives a different
180 # result. If it does then we switch over to complex testing. This
181 # means that we will be somewhat delayed in finding link problems that
182 # only complex mode discovers
183  
184 # =cut
185  
186  
187 sub BANNED_SIMPLE () {1<<1;}
188 sub BANNED_COMPLEX () {1<<2;}
189  
190 #sub CHECK_UNDETERMINED () {1<<3;}
191  
192 sub CHECK_VERIFY_WORKING_SIMPLE () {1<<6;}
193 sub CHECK_VERIFY_BROKEN_SIMPLE () {1<<6;}
194  
195 sub UNTESTABLE_SIMPLE () {1<<7;}
196 sub UNTESTABLE_COMPLEX () {1<<8;}
197  
198 sub LAST_SIMPLE_WORKING () {1<<8;}
199  
200 #testing modes to return
201 82 ▶sub MODE_SIMPLE {1;}
Subroutine MODE_SIMPLE: called CC=1 SCAR=0.0
202 72 ▶sub MODE_COMPLEX {2;}
Subroutine MODE_COMPLEX: called CC=1 SCAR=0.0
203  
204 4 ▶sub TIME_SHORT {1;}
Subroutine TIME_SHORT: called CC=1 SCAR=0.0
205 24 ▶sub TIME_NORMAL {2;}
Subroutine TIME_NORMAL: called CC=1 SCAR=0.0
206  
207 0 ▶sub UPDATE_LINK {1;}
Subroutine UPDATE_LINK: not called CC=1 SCAR=6.9
208 0 ▶sub TRY_ONLY {2;}
Subroutine TRY_ONLY: not called CC=1 SCAR=6.9
209  
210 #switch over triggers. We mostly want to test complex
211 sub TRY_COMPLEX_EVERY_SIMPLE () {11;}
212 sub TRY_SIMPLE_EVERY_COMPLEX () {5;}
213  
214 #how many inconsistent tests before we decide it's a sure problem
215 sub STABLE_INCONSISTENT () {3;}
216 sub PART_INCONSISTENT () {1;}
217  
218 18 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
219 18 my $s=shift;
220 18 ▶ my $class = ref($s) || $s;
Condition33%1/3
ref $s || $s
l!l&&r!l&&!r
0180
MC/DC0%0/2
ref $s || $s
ref $s $s
Truth table33%1/3
A || B
A= ref $sB= $s
ABresult
1X1
011
000
221 18 my $self={};
222 18 $self->{settings}=0 ;
223 18 bless $self, $class;
224 }
225  
226 #fixme: special cases
227 #link is suspicious (others on server look broken)
228 #link has just changed status?
229  
230 28 ▶sub calculate_test_state {
Subroutine calculate_test_state: called CC=27 SCAR=36.5
231 28 my $self=shift;
232 28 my $link=shift;
233  
234 28 ▶ defined $self->{'simple'} && do {
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"simple"} and do { warn "deleting \$self->{simple} from cookie"; delete $self->{"simple"} } 0 28 28
235 0 warn 'deleting $self->{simple} from cookie';
236 0 delete $self->{'simple'};
237 };
238  
239 28 ▶ defined $self->{'complex'} && do {
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"complex"} and do { warn "deleting \$self->{complex} from cookie"; delete $self->{"complex"} } 0 28 28
240 0 warn 'deleting $self->{complex} from cookie';
241 0 delete $self->{'complex'};
242 };
243  
244 28 ▶ defined $self->{settings} or $self->{settings}=0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"settings"} or $self->{"settings"} = 0 28 0 28
245 28 my $settings=$self->{settings};
246  
247 #user controlled cases
248 28 ▶ $settings & BANNED_SIMPLE && $settings & BANNED_COMPLEX and
Branch: 1 branch
BranchTrueFalseTotal
$settings & 2 and $settings & 4 and die "banned from both simple and complex testing" 0 28 28
Condition33%1/3
$settings & 2 and $settings & 4
!ll&&!rl&&r
2800
MC/DC0%0/2
$settings & 2 and $settings & 4
$settings & 2 $settings & 4
Truth table33%1/3
A and B
A= $settings & 2B= $settings & 4
ABresult
0X0
100
111
249 die "banned from both simple and complex testing";
250 28 ▶ $settings & BANNED_SIMPLE && return MODE_SIMPLE;
Branch: 1 branch
BranchTrueFalseTotal
$settings & 2 and return MODE_SIMPLE() 0 28 28
251 28 ▶ $settings & BANNED_COMPLEX && return MODE_COMPLEX;
Branch: 1 branch
BranchTrueFalseTotal
$settings & 4 and return MODE_COMPLEX() 0 28 28
252  
253 28 my $url=$link->url();
254 28 my $count=$link->testcount();
255  
256 #now look at history..
257 28 my @responses=@_;
258  
259 28 ▶ for (my $i=0; @responses < 4; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (@responses < 4) 82 16 98
260 82 my @resp=$link->recover_response($i);
261 82 ▶ @resp or last;
Branch: 1 branch
BranchTrueFalseTotal
@resp or last 70 12 82
262 70 ▶ defined $resp[2] or do {
Branch: 1 branch
BranchTrueFalseTotal
defined $resp[2] or do { warn "last tester not recorded"; last } 70 0 70
263 0 warn "last tester not recorded";
264 0 last;
265 };
266 70 ▶ last unless $resp[2] eq "WWW::Link::Tester::Adaptive";
Branch: 1 branch
BranchTrueFalseTotal
unless $resp[2] eq "WWW::Link::Tester::Adaptive" 0 70 70
267 70 push @responses, \@resp;
268 }
269 28 my $inconsistency = 0;
270 28 foreach (@{$self->{test_consistency}}) {
271 45 ▶ next unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 28 17 45
272 17 ▶ $inconsistency = $_ if $_ > $inconsistency;
Branch: 1 branch
BranchTrueFalseTotal
if $_ > $inconsistency 15 2 17
273 }
274  
275 28 ▶ print STDERR "link inconsistency $inconsistency\n"
Branch: 1 branch
BranchTrueFalseTotal
if $WWW::Link::Tester::Adaptive::Cookie::verbose 0 28 28
276 if $verbose;
277  
278 CASE: {
279  
280 28 ▶ $inconsistency <= 0 && do {
Branch: 1 branch
BranchTrueFalseTotal
$inconsistency <= 0 and do { $count % 11 == 10 and return MODE_COMPLEX(), TIME_NORMAL(); print STDERR "returning simple for normal testing\n" if $WWW::Link::Tester::Adaptive::Cookie::verbose; return MODE_SIMPLE(), TIME_NORMAL() } 19 9 28
281 19 ▶ ( $count % TRY_COMPLEX_EVERY_SIMPLE )
Branch: 1 branch
BranchTrueFalseTotal
$count % 11 == 10 and return MODE_COMPLEX(), TIME_NORMAL() 1 18 19
282 == ( TRY_COMPLEX_EVERY_SIMPLE - 1 )
283 and return MODE_COMPLEX, TIME_NORMAL;
284 18 ▶ print STDERR "returning simple for normal testing\n"
Branch: 1 branch
BranchTrueFalseTotal
if $WWW::Link::Tester::Adaptive::Cookie::verbose 0 18 18
285 if $verbose;
286 18 return MODE_SIMPLE, TIME_NORMAL;
287 };
288  
289 9 ▶ $inconsistency < STABLE_INCONSISTENT && do {
Branch: 1 branch
BranchTrueFalseTotal
$inconsistency < 3 and do { if ($responses[0][3] == MODE_COMPLEX()) { print STDERR "returning simple for instability testing\n" if $WWW::Link::Tester::Adaptive::Cookie::verbose; return MODE_SIMPLE(), TIME_SHORT(); } else { print STDERR "returning complex for instability testing\n" if $WWW::Link::Tester::Adaptive::Cookie::verbose; return MODE_COMPLEX(), TIME_NORMAL(); } } 4 5 9
290 4 ▶ if ( $responses[0][3] == MODE_COMPLEX){
Branch: 1 branch
BranchTrueFalseTotal
if ($responses[0][3] == MODE_COMPLEX()) { } 2 2 4
291 2 ▶ print STDERR "returning simple for instability testing\n"
Branch: 1 branch
BranchTrueFalseTotal
if $WWW::Link::Tester::Adaptive::Cookie::verbose 0 2 2
292 if $verbose;
293 2 return MODE_SIMPLE, TIME_SHORT;
294 } else {
295 2 ▶ print STDERR "returning complex for instability testing\n"
Branch: 1 branch
BranchTrueFalseTotal
if $WWW::Link::Tester::Adaptive::Cookie::verbose 0 2 2
296 if $verbose;
297 2 return MODE_COMPLEX, TIME_NORMAL;
298 }
299 };
300  
301 5 ▶ $inconsistency >= STABLE_INCONSISTENT && do {
Branch: 1 branch
BranchTrueFalseTotal
$inconsistency >= 3 and do { $count % 5 == 4 and do { print STDERR "returning simple incase it's working again\n" if $WWW::Link::Tester::Adaptive::Cookie::verbose; return MODE_SIMPLE(), TIME_SHORT() }; print STDERR "returning complex for careful testing\n" if $WWW::Link::Tester::Adaptive::Cookie::verbose; return MODE_COMPLEX(), TIME_NORMAL() } 5 0 5
302 ( $count % TRY_SIMPLE_EVERY_COMPLEX )
303 == ( TRY_SIMPLE_EVERY_COMPLEX - 1 )
304 5 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$count % 5 == 4 and do { print STDERR "returning simple incase it's working again\n" if $WWW::Link::Tester::Adaptive::Cookie::verbose; return MODE_SIMPLE(), TIME_SHORT() } 2 3 5
305 2 ▶ print STDERR "returning simple incase it's working again\n"
Branch: 1 branch
BranchTrueFalseTotal
if $WWW::Link::Tester::Adaptive::Cookie::verbose 0 2 2
306 if $verbose;
307 2 return MODE_SIMPLE, TIME_SHORT;
308 };
309 3 ▶ print STDERR "returning complex for careful testing\n"
Branch: 1 branch
BranchTrueFalseTotal
if $WWW::Link::Tester::Adaptive::Cookie::verbose 0 3 3
310 if $verbose;
311 3 return MODE_COMPLEX, TIME_NORMAL;
312 };
313 0 die "no inconsistency value";
314 }
315  
316 0 die "shouldn't get here";
317 }
318  
319 # =comment
320  
321 # we've just done a test
322 # we aren't going to apply it to the link.
323 # we should see if it changes anything about our opionion
324  
325 # we return 1 if we think that this response is good for applying to the link.
326  
327 # =cut
328  
329 29 ▶sub consider_test {
Subroutine consider_test: called CC=22 SCAR=32.4
330 29 my $self=shift;
331 29 my $link=shift;
332  
333 29 my $response=shift;
334 29 my $mode=shift;
335  
336 29 my ($old_response,$old_time,$old_tester,$old_mode)
337 = $link->recover_response(0);
338  
339 29 ▶ defined $old_response or return 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $old_response or return 1 20 9 29
340 20 ▶ defined $old_mode or do {
Branch: 1 branch
BranchTrueFalseTotal
defined $old_mode or do { warn "old mode not defined; treating as first test"; return 1 } 20 0 20
341 0 warn "old mode not defined; treating as first test";
342 0 return 1;
343 };
344  
345 # ($old_response,$old_time,$old_tester,$old_mode)
346 # = ($self->{try_response}, $self->{try_time}, undef, $self->{try_mode})
347 # if defined $self->{try_response} and $self->{try_time} > $old_time;
348  
349 20 my $apply=0;
350  
351 20 ▶ die "mode not defined" unless defined $mode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mode 0 20 20
352  
353 20 ▶ $self->{test_consistency} = [] unless defined $self->{test_consistency};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"test_consistency"} 0 20 20
354  
355 20 ▶ print STDERR "mode is $mode and old mode is $old_mode\n"
Branch: 1 branch
BranchTrueFalseTotal
if $WWW::Link::Tester::Adaptive::Cookie::verbose 0 20 20
356 if $verbose;
357 20 ▶ print STDERR "simple is ". MODE_SIMPLE
Branch: 1 branch
BranchTrueFalseTotal
if $WWW::Link::Tester::Adaptive::Cookie::verbose 0 20 20
358 . " and complex is " . MODE_COMPLEX . "\n" if $verbose;
359  
360  
361 #unsupported protocols should always be handled by simple by
362 #default. It's also possible for simple to handle some protocols
363 #that complex doesn't although this is not a good situation.
364  
365 ( $mode == MODE_COMPLEX and $response->code == RC_PROTOCOL_UNSUPPORTED )
366 20 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$mode == MODE_COMPLEX() and $response->code == 498 and do { $self->{"test_consistency"} = []; return 1 } 1 19 20
Condition100%3/3
$mode == MODE_COMPLEX() and $response->code == 498
!ll&&!rl&&r
1361
MC/DC100%2/2
$mode == MODE_COMPLEX() and $response->code == 498
$mode == MODE_COMPLEX() $response->code == 498
Truth table100%3/3
A and B
A= $mode == MODE_COMPLEX()B= $response->code == 498
ABresult
0X0
100
111
367 1 $self->{test_consistency} = [];
368 1 return 1;
369 };
370  
371 ( $mode == MODE_SIMPLE and $old_mode == MODE_COMPLEX )
372 19 ▶ || ( $mode == MODE_COMPLEX and $old_mode == MODE_SIMPLE ) and do {
Branch: 1 branch
BranchTrueFalseTotal
$mode == MODE_SIMPLE() && $old_mode == MODE_COMPLEX() || $mode == MODE_COMPLEX() && $old_mode == MODE_SIMPLE() and do { print STDERR "considering consistency of last two tests\n" if $WWW::Link::Tester::Adaptive::Cookie::verbose; my $scode = short_code($mode == MODE_SIMPLE() ? $old_response->code : $old_response->code); $self->{"test_consistency"}[$scode] = 0 unless defined $self->{"test_consistency"}[$scode]; if ($self->responses_are_equivalent($response, $old_response)) { if ($self->{"test_consistency"}[$scode] > 3) { $self->{"test_consistency"}[$scode] = 1; } else { $self->{"test_consistency"}[$scode] = 0; } ; } else { ++$self->{"test_consistency"}[short_code($old_response->code)]; return $mode == MODE_COMPLEX(); } } 7 12 19
Condition100%9/9
$mode == MODE_SIMPLE() and $old_mode == MODE_COMPLEX() or $mode == MODE_COMPLEX() and $old_mode == MODE_SIMPLE()
l!l&&r!l&&!r
3412
$mode == MODE_SIMPLE() and $old_mode == MODE_COMPLEX()
!ll&&!rl&&r
6103
$mode == MODE_COMPLEX() and $old_mode == MODE_SIMPLE()
!ll&&!rl&&r
1024
MC/DC75%3/4
$mode == MODE_SIMPLE() and $old_mode == MODE_COMPLEX() or $mode == MODE_COMPLEX() and $old_mode == MODE_SIMPLE()
$mode == MODE_SIMPLE() $old_mode == MODE_COMPLEX() $mode == MODE_COMPLEX() $old_mode == MODE_SIMPLE()
Truth table57%4/7
A and B or C and D
A= $mode == MODE_SIMPLE()B= $old_mode == MODE_COMPLEX()C= $mode == MODE_COMPLEX()D= $old_mode == MODE_SIMPLE()
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
373 7 ▶ print STDERR "considering consistency of last two tests\n"
Branch: 1 branch
BranchTrueFalseTotal
if $WWW::Link::Tester::Adaptive::Cookie::verbose 0 7 7
374 if $verbose;
375 7 ▶ my $scode = short_code( ($mode == MODE_SIMPLE)
Branch: 1 branch
BranchTrueFalseTotal
$mode == MODE_SIMPLE() ? : 3 4 7
376 ? $old_response->code
377 : $old_response->code );
378 $self->{test_consistency}[$scode]=0
379 7 ▶ unless defined $self->{test_consistency}[$scode];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"test_consistency"}[$scode] 2 5 7
380 7 ▶ if ( $self->responses_are_equivalent( $response, $old_response) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->responses_are_equivalent($response, $old_response)) { } 0 7 7
381 0 ▶ if ( $self->{test_consistency}[$scode] > STABLE_INCONSISTENT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'test_consistency'}[$scode] > 3) { } 0 0 0
382 0 $self->{test_consistency}[$scode] = PART_INCONSISTENT;
383 } else {
384 0 $self->{test_consistency}[$scode] = 0;
385 }
386 } else {
387 7 $self->{test_consistency}[short_code($old_response->code)]++;
388 # inconsistent test so we don't want to reduce consistency of other
389 # codes; return now
390 7 return $mode == MODE_COMPLEX ;
391 }
392 };
393  
394  
395 # inconsistency can be caused by intermittent network problems...
396 # we decay it away if it isn't confirmed.
397  
398 # FIXME: maybe we shouldn't do this when we have a known
399 # inconsistent link?
400  
401 12 foreach my $inconsistency (@{$self->{test_consistency}}) {
402 15 ▶ next unless defined $inconsistency;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $inconsistency 9 6 15
403 6 ▶ $inconsistency -= 0.3 if $inconsistency < STABLE_INCONSISTENT;
Branch: 1 branch
BranchTrueFalseTotal
if $inconsistency < 3 3 3 6
404 6 ▶ $inconsistency = 0 if $inconsistency < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $inconsistency < 0 0 6 6
405 }
406  
407 12 return 1;
408 }
409  
410 sub INTER_TEST_DELAY() {60 * 60 * 1};
411  
412 0 ▶sub time_want_test {
Subroutine time_want_test: not called CC=3 SCAR=24.8
413 0 my ($self, $link)=@_;
414 0 ▶ die 'usage $cookie->time_want_test($link)' unless ref $link;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $link 0 0 0
415 0 my (undef, $time)=$self->calculate_test_state;
416 0 ▶ return INTER_TEST_DELAY if $time & TIME_SHORT;
Branch: 1 branch
BranchTrueFalseTotal
if $time & TIME_SHORT() 0 0 0
417 0 return undef;
418 }
419  
420 # =scode
421  
422 # short code - returns the first digit of a response code. The first
423 # digit represents the class.
424  
425 # =cut
426  
427 28 ▶sub short_code {
Subroutine short_code: called CC=2 SCAR=7.0
428 28 my $code=shift;
429 28 ▶ die "invalid code $code" unless
Branch: 1 branch
BranchTrueFalseTotal
unless $code =~ /^[1-9][0-9][0-9]$/ 0 28 28
430 $code =~ m/^[1-9][0-9][0-9]$/;
431 28 $code =~ s/^([1-9])[0-9][0-9]$/$1/;
432 28 return $code;
433 }
434  
435 # =comment
436  
437 # responses_are_equivalent - returns true if two responses can be
438 # considered equivalent from the point of view of testing.
439  
440 # =cut
441  
442 7 ▶sub responses_are_equivalent {
Subroutine responses_are_equivalent: called CC=1 SCAR=0.0
443 7 my ($self, $resp_a, $resp_b)=@_;
444  
445 7 my $scode_a=short_code($resp_a->code);
446 7 my $scode_b=short_code($resp_b->code);
447  
448 7 return $scode_a == $scode_b;
449  
450 }
451  
452  
453 3 1; #kEEp rEqUIrE HaPpY.
« Link/Reporter/LongList.pm ↑ Summary Link.pm »