1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#!perl
# vim:ft=perl:
#
# This script tests whether timeout actually works.
use strict;
use warnings;
use Test::More;
use Error qw(:try);
use IO::Socket;
use RT::Client::REST;
use LWP::UserAgent;
plan( skip_all => "LWP::UserAgent 6.04 does not know how to time out, ".
"see RT #81799" ) if $LWP::UserAgent::VERSION eq '6.04';
my $server = IO::Socket::INET->new(
Type => SOCK_STREAM,
Reuse => 1,
Listen => 10,
) or die "Could not set up TCP server: $@";
my $port = $server->sockport;
my $pid = fork; # Fork
die "Could not fork: $!" unless defined $pid;
if (0 == $pid) { # Child
my $buf;
my $client = $server->accept;
1 while ($client->read($buf, 1024));
exit;
}
plan tests => 8; # Parent
for my $timeout (1, 2, 5, 10) {
my $rt = RT::Client::REST->new(
server => "http://127.0.0.1:$port",
timeout => $timeout,
);
my $t1 = time;
my ($e, $t2);
try {
$rt->login(qw(username a password b));
} catch Exception::Class::Base with {
$t2 = time;
$e = shift;
};
isa_ok($e, 'RT::Client::REST::RequestTimedOutException');
ok($t2 - $t1 >= $timeout, "Timed out after $timeout seconds");
}
|