forked from mala/AnyEvent-Curl
/
03_timeout.t
47 lines (39 loc) · 1.09 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
use Test::More;
use t::Test;
use Data::Dumper;
use HTTP::Request::Common;
use Plack::Request;
test_psgi(
app => sub {
my $env = shift;
my $req = Plack::Request->new($env);
sleep 2;
return [ 200, [ 'Content-Type' => 'text/plain' ], ["Hellow World after 2 sec"] ];
},
client => sub {
my $cb = shift;
my $req = HTTP::Request->new(GET => "http://localhost/hello");
my $cv = $cb->($req, sub{}, {timeout => 1});
my $res = $cv->recv;
ok( !$res->is_success, "fail by timeouot" );
}
);
test_psgi(
app => sub {
my $env = shift;
my $req = Plack::Request->new($env);
sleep 2;
return [ 200, [ 'Content-Type' => 'text/plain' ], ["Hellow World after 2 sec"] ];
},
client => sub {
my $cb = shift;
my $req = HTTP::Request->new(GET => "http://localhost/hello");
my $cv = $cb->($req, sub{}, {timeout => 10});
my $res = $cv->recv;
ok( $res->is_success, "check status code" );
like( $res->content, qr/Hellow World/, "content");
isa_ok( $res->http_response, "HTTP::Response", "generate http response" );
warn "done client";
}
);
done_testing;