Skip to content

Commit ec34824

Browse files
committed
add t/url.t
1 parent 3344fe1 commit ec34824

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

t/url.t

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use strict;
2+
use warnings;
3+
4+
use Test::More 0.98;
5+
6+
use Config;
7+
use HTTP::Daemon;
8+
use HTTP::Response;
9+
use HTTP::Tiny;
10+
11+
my $can_fork
12+
= $Config{d_fork}
13+
|| (($^O eq 'MSWin32' || $^O eq 'NetWare')
14+
and $Config{useithreads}
15+
and $Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/);
16+
17+
plan skip_all => "This system cannot fork" if !$can_fork;
18+
19+
my $d = HTTP::Daemon->new or die "HTTP::Daemon->new: $!";
20+
21+
my $url = $d->url;
22+
note "url: $url";
23+
24+
my $pid = fork;
25+
die "fork: $!" if !defined $pid;
26+
27+
if ($pid == 0) {
28+
my $http = HTTP::Tiny->new(
29+
timeout => 3,
30+
proxy => undef,
31+
http_proxy => undef,
32+
https_proxy => undef,
33+
);
34+
my $res;
35+
eval {
36+
local $SIG{ALRM} = sub { die "alarm\n" };
37+
alarm 4;
38+
$res = $http->get($url);
39+
};
40+
my $err = $@;
41+
alarm 0;
42+
exit if $res && $res->{success};
43+
if ($err) {
44+
diag $err;
45+
}
46+
if ($res) {
47+
diag "$res->{status} $res->{reason}";
48+
diag $res->{content} if $res->{status} == 599;
49+
}
50+
exit 1;
51+
}
52+
53+
my $c = $d->accept or die "accept: $!";
54+
my $req = $c->get_request;
55+
$c->send_response(HTTP::Response->new(200));
56+
$c->close;
57+
$d->close;
58+
59+
wait;
60+
is $?, 0;
61+
62+
done_testing;

0 commit comments

Comments
 (0)