/
12-close-on-drop.t
64 lines (53 loc) · 1.25 KB
/
12-close-on-drop.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
62
63
64
#!perl
use warnings;
use strict;
use Test::More tests => 14;
use Test::Exception;
use lib 't'; use Utils;
BEGIN { use_ok('Feersum') };
my ($socket,$port) = get_listen_socket();
ok $socket, "made listen socket";
my $evh = Feersum->new();
{
no warnings 'redefine';
*Feersum::DIED = sub {
my $err = shift;
fail "Died during request handler: $err";
};
}
$evh->request_handler(sub {
my $r = shift;
ok $r, 'got request';
my $w = $r->start_streaming(200, []);
$w->write("hello ");
$w->write("world!\n");
lives_ok {
undef $w;
} 'no death on undef';
});
lives_ok {
$evh->use_socket($socket);
} 'assigned socket';
my $cv = AE::cv;
sub client {
my $cnum = shift;
my $is_chunked = shift || 0;
$cv->begin;
my $h; $h = simple_client GET => '/foo',
name => "client $cnum",
timeout => 15,
proto => $is_chunked ? '1.1' : '1.0',
headers => {"Accept" => "*/*"},
sub {
my ($body, $headers) = @_;
is $headers->{Status}, 200, "client $cnum got 200"
or diag $headers->{Reason};
is $body, "hello world!\n", "client $cnum body";
$cv->end;
undef $h;
};
}
client(1,'chunked');
client(2);
$cv->recv;
pass "all done";