Skip to content

Commit

Permalink
Mock responses to avoid unnecessary network requests
Browse files Browse the repository at this point in the history
fixes rt-71491 where network tests sometimes hang indefinitely.
  • Loading branch information
rwstauner committed Nov 4, 2011
1 parent 2aa8b0e commit 2fce08c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions t/10_determined_test.t
Expand Up @@ -9,6 +9,16 @@ BEGIN { plan tests => 13 }
use LWP::UserAgent::Determined; use LWP::UserAgent::Determined;
my $browser = LWP::UserAgent::Determined->new; my $browser = LWP::UserAgent::Determined->new;


use HTTP::Headers;
use HTTP::Request;

sub set_response {
my ($code) = @_;
$browser->set_my_handler(request_send => @_ ? sub {
return HTTP::Response->new($code, undef, HTTP::Headers->new(), 'n/a');
} : ());
}

sub timings { sub timings {
my $self = $browser; my $self = $browser;
# copied from module, line 20 # copied from module, line 20
Expand All @@ -27,6 +37,10 @@ my @error_codes = qw(408 500 502 503 504);
ok( @error_codes == keys %{$browser->codes_to_determinate} ); ok( @error_codes == keys %{$browser->codes_to_determinate} );
ok( @error_codes == grep { $browser->codes_to_determinate->{$_} } @error_codes ); ok( @error_codes == grep { $browser->codes_to_determinate->{$_} } @error_codes );


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

set_response(503);

my $url = 'http://www.livejournal.com/~torgo_x/rss'; my $url = 'http://www.livejournal.com/~torgo_x/rss';
my $before_count = 0; my $before_count = 0;
my $after_count = 0; my $after_count = 0;
Expand All @@ -52,6 +66,8 @@ ok( $after_count > 1 );


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


set_response(500);

$url = "http://www.aoeaoeaoeaoe.int:9876/sntstn"; $url = "http://www.aoeaoeaoeaoe.int:9876/sntstn";
$before_count = 0; $before_count = 0;
$after_count = 0; $after_count = 0;
Expand All @@ -73,6 +89,8 @@ ok $after_count, 4;


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


set_response(404);

$url = "http://www.interglacial.com/always404alicious/"; $url = "http://www.interglacial.com/always404alicious/";
$before_count = 0; $before_count = 0;
$after_count = 0; $after_count = 0;
Expand Down

0 comments on commit 2fce08c

Please sign in to comment.