Skip to content

Commit

Permalink
Skip IPv6 tests if they're run on a machine that can't resolve IPv6 a…
Browse files Browse the repository at this point in the history
…ddresses. We assume localhost can resolve.
  • Loading branch information
apocalypse authored and rcaputo committed Jan 27, 2011
1 parent a7a1411 commit d0a5045
Showing 1 changed file with 56 additions and 34 deletions.
90 changes: 56 additions & 34 deletions t/01-basic.t
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,20 +14,38 @@ my $r4 = POE::Component::Resolver->new(
af_order => [ AF_INET ], af_order => [ AF_INET ],
); );


my $r6 = POE::Component::Resolver->new( # Try to detect whether we can resolve IPv6 addresses at all.
max_resolvers => 1,
af_order => [ AF_INET6 ], use Socket::GetAddrInfo qw(:newapi getaddrinfo);
); my $has_ipv6 = do {

my ($error, @addresses) = getaddrinfo(
my $r46 = POE::Component::Resolver->new( "localhost", "www", { family => AF_INET6 }
max_resolvers => 1, );
af_order => [ AF_INET, AF_INET6 ], ($error or not @addresses) ? 0 : 1;
); };


my $r64 = POE::Component::Resolver->new( # If we can't, don't bother setting up resolvers for them.
max_resolvers => 1,
af_order => [ AF_INET6, AF_INET ], my ($r6, $r46, $r64);
); if ($has_ipv6) {
$r6 = POE::Component::Resolver->new(
max_resolvers => 1,
af_order => [ AF_INET6 ],
);

$r46 = POE::Component::Resolver->new(
max_resolvers => 1,
af_order => [ AF_INET, AF_INET6 ],
);

$r64 = POE::Component::Resolver->new(
max_resolvers => 1,
af_order => [ AF_INET6, AF_INET ],
);
}

# TODO - Not robust to try a single remote host. I fully expect this
# to bite me later, unless someone wants to take a shot at it.


my $host = 'ipv6-test.com'; my $host = 'ipv6-test.com';
my $tcp = getprotobyname("tcp"); my $tcp = getprotobyname("tcp");
Expand All @@ -42,26 +60,30 @@ POE::Session->create(
misc => [ AF_INET ], misc => [ AF_INET ],
) or die $!; ) or die $!;


$r6->resolve( SKIP: {
host => $host, skip("IPv6 not detected; skipping IPv6 tests", 3) unless $has_ipv6;
service => 'http',
hints => { protocol => $tcp }, $r6->resolve(
misc => [ AF_INET6 ], host => $host,
) or die $!; service => 'http',

hints => { protocol => $tcp },
$r46->resolve( misc => [ AF_INET6 ],
host => $host, ) or die $!;
service => 'http',
hints => { protocol => $tcp }, $r46->resolve(
misc => [ AF_INET, AF_INET6 ], host => $host,
) or die $!; service => 'http',

hints => { protocol => $tcp },
$r64->resolve( misc => [ AF_INET, AF_INET6 ],
host => $host, ) or die $!;
service => 'http',
hints => { protocol => $tcp }, $r64->resolve(
misc => [ AF_INET6, AF_INET ], host => $host,
) or die $!; service => 'http',
hints => { protocol => $tcp },
misc => [ AF_INET6, AF_INET ],
) or die $!;
}
}, },


resolver_response => sub { resolver_response => sub {
Expand Down

0 comments on commit d0a5045

Please sign in to comment.