Permalink
Browse files

Mock responses to avoid unnecessary network requests

fixes rt-71491 where network tests sometimes hang indefinitely.
  • Loading branch information...
1 parent 2aa8b0e commit 2fce08c7d82648087479b80bf0aec33609c44631 @rwstauner rwstauner committed Nov 4, 2011
Showing with 18 additions and 0 deletions.
  1. +18 −0 t/10_determined_test.t
@@ -9,6 +9,16 @@ BEGIN { plan tests => 13 }
use LWP::UserAgent::Determined;
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 {
my $self = $browser;
# copied from module, line 20
@@ -27,6 +37,10 @@ my @error_codes = qw(408 500 502 503 504);
ok( @error_codes == keys %{$browser->codes_to_determinate} );
ok( @error_codes == grep { $browser->codes_to_determinate->{$_} } @error_codes );
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+set_response(503);
+
my $url = 'http://www.livejournal.com/~torgo_x/rss';
my $before_count = 0;
my $after_count = 0;
@@ -52,6 +66,8 @@ ok( $after_count > 1 );
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+set_response(500);
+
$url = "http://www.aoeaoeaoeaoe.int:9876/sntstn";
$before_count = 0;
$after_count = 0;
@@ -73,6 +89,8 @@ ok $after_count, 4;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+set_response(404);
+
$url = "http://www.interglacial.com/always404alicious/";
$before_count = 0;
$after_count = 0;

0 comments on commit 2fce08c

Please sign in to comment.