ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/81_hosts.t
Revision: 1.1
Committed: Wed Aug 21 08:40:28 2013 UTC (10 years, 10 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-7_05
Log Message:
7.05

File Contents

# User Rev Content
1 root 1.1 use File::Temp qw(tempfile);
2     use Test::More tests => 2;
3    
4     my $test_host = 'test.invalid.tld';
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