/
03-timeout.t
61 lines (48 loc) · 1.2 KB
/
03-timeout.t
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
56
57
58
59
60
61
use strict;
use warnings;
use 5.010;
use Test::TCP;
use Test::More;
use Test::Requires qw(Plack::Builder Plack::Handler::Twiggy);
use Test::Requires { 'Plack::Request' => '0.99' };
use Mouse::Object;
use AnyEvent::Peer39;
plan tests => 2;
test_tcp(
client => sub {
my $port = shift;
my $url = "http://localhost:$port";
my $client = AnyEvent::Peer39->new(
account_name => "test",
api_key => 'secret',
base_url => $url,
);
my $cv = AE::cv;
$cv->begin;
$client->get_page_info(
remote_url => 'http://foo',
cb => sub {
my ($response) = @_;
ok $response->is_failure;
is $response->message, "Connection timed out";
$cv->end;
}
);
$cv->recv;
},
server => sub {
my $port = shift;
my $app = builder {
mount '/proxy/targeting' => sub {
return sub {
sleep 2;
return shift->([204, [], ['']]);
}
}
};
my $server = Plack::Handler::Twiggy->new(
host => '127.0.0.1',
port => $port,
)->run($app);
},
);