ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/03_http_req.t
Revision: 1.4
Committed: Sun Apr 27 19:41:31 2008 UTC (16 years, 2 months ago) by elmex
Content type: application/x-troff
Branch: MAIN
Changes since 1.3: +1 -1 lines
Log Message:
http test doesn't hang anymore when connection failed

File Contents

# User Rev Content
1 elmex 1.1 #!/opt/perl/bin/perl
2 root 1.3
3 elmex 1.1 use strict;
4 elmex 1.2 use Test::More;
5 root 1.3 use AnyEvent::Impl::Perl;
6 elmex 1.1 use AnyEvent;
7     use AnyEvent::Socket;
8    
9 elmex 1.2 unless ($ENV{PERL_ANYEVENT_NET_TESTS}) {
10     plan skip_all => "PERL_ANYEVENT_NET_TESTS environment variable not set";
11     exit 0;
12     }
13    
14     plan tests => 2;
15    
16 elmex 1.1 my $cv = AnyEvent->condvar;
17    
18     my $fbytes;
19     my $rbytes;
20    
21     my $ae_sock =
22     AnyEvent::Socket->new (
23     PeerAddr => "www.google.de:80",
24     on_eof => sub { $cv->broadcast },
25     on_error => sub {
26     my ($ae_sock) = @_;
27     diag "error: $!";
28     $cv->broadcast
29     },
30     on_connect => sub {
31     my ($ae_sock, $error) = @_;
32 elmex 1.4 if ($error) { diag ("connect error: $!"); $cv->broadcast; return }
33 elmex 1.1
34     $ae_sock->read (10, sub {
35     my ($ae_sock, $data) = @_;
36     $fbytes = $data;
37    
38     $ae_sock->on_read (sub {
39     my ($ae_sock) = @_;
40     $rbytes = $ae_sock->rbuf;
41     });
42     });
43    
44     $ae_sock->write ("GET http://www.google.de/ HTTP/1.0\015\012\015\012");
45     }
46     );
47    
48     $cv->wait;
49    
50     is (substr ($fbytes, 0, 4), 'HTTP', 'first bytes began with HTTP');
51     ok ($rbytes =~ /google.*<\/html>\s*$/i, 'content was retrieved successfully');