ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/81_hosts.t
Revision: 1.3
Committed: Thu Oct 3 17:50:04 2013 UTC (10 years, 9 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-7_07, rel-7_16, rel-7_15, rel-7_14, rel-7_13, rel-7_12, rel-7_11, rel-7_08, rel-7_09, HEAD
Changes since 1.2: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 use File::Temp qw(tempfile);
2 use Test::More tests => 2;
3
4 my $test_host = 'test.invalid.';
5 my $test_addr = '127.9.9.9';
6
7 my ($hosts_fh, $hosts_file) = tempfile UNLINK => 1;
8 print $hosts_fh "$test_addr $test_host\n";
9 close $hosts_fh;
10
11 $ENV{PERL_ANYEVENT_HOSTS} = $hosts_file;
12
13 require AnyEvent;
14 require AnyEvent::Socket;
15
16 sub resolved($) {
17 my $cv = AnyEvent->condvar;
18
19 AnyEvent::Socket::resolve_sockaddr (shift, 80, undef, undef, undef, sub {
20 return $cv->send unless @_;
21 my $sockaddr = $_[0][-1];
22 my $address = (AnyEvent::Socket::unpack_sockaddr ($sockaddr))[1];
23 return $cv->send (AnyEvent::Socket::format_address ($address));
24 });
25
26 return $cv->recv;
27 }
28
29 is resolved $test_host, $test_addr, 'resolved on first attempt';
30 is resolved $test_host, $test_addr, 'resolved on second attempt';
31