Skip to content

Commit

Permalink
improved non-blocking resolver by allowing it to be disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 13, 2011
1 parent 164701e commit 62057f8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -10,6 +10,7 @@ This file documents the revision history for Perl extension Mojolicious.
- Improved documentation. (rhaen, sri)
- Improved test command to run tests in alphabetical order.
(viliampucik)
- Improved non-blocking resolver by allowing it to be disabled.
- Improved tests.
- Fixed small bug in cookie jar.
- Fixed small plugin loader bug.
Expand Down
5 changes: 4 additions & 1 deletion lib/Mojo/IOLoop/Resolver.pm
Expand Up @@ -135,7 +135,10 @@ sub resolve {
my $loop = $self->ioloop;
weaken $self;
return $loop->defer(sub { $self->$cb([]) })
if !$server || !$t || ($t ne $DNS_TYPES->{PTR} && ($v4 || $v6));
if $ENV{MOJO_NO_RESOLVER}
|| !$server
|| !$t
|| ($t ne $DNS_TYPES->{PTR} && ($v4 || $v6));

# Build request
warn "RESOLVE $type $name ($server)\n" if DEBUG;
Expand Down
7 changes: 7 additions & 0 deletions lib/Mojolicious/Guides/Cheatsheet.pod
Expand Up @@ -271,6 +271,13 @@ Note that L<IO::Socket::IP> must be installed for IPv6 support.

MOJO_NO_IPV6=1

=head2 C<MOJO_NO_RESOLVER>

Disable non-blocking resolver support and fall back to blocking system
resolver.

MOJO_NO_RESOLVER=1

=head2 C<MOJO_NO_TLS>

Disable TLS support, this might result in slightly better performance and
Expand Down
31 changes: 30 additions & 1 deletion t/mojo/resolver_online.t
Expand Up @@ -11,7 +11,7 @@ use Test::More;
plan skip_all => 'set TEST_ONLINE to enable this test (developer only!)'
unless $ENV{TEST_ONLINE};
plan skip_all => 'Perl 5.12 required for this test!' unless $] >= 5.012;
plan tests => 18;
plan tests => 20;

use_ok 'Mojo::IOLoop';

Expand Down Expand Up @@ -49,6 +49,35 @@ $r->lookup(
Mojo::IOLoop->start;
ok $result, 'got an address';

# Lookup with disabled resolver
$result = undef;
my $backup = $ENV{MOJO_NO_RESOLVER};
$ENV{MOJO_NO_RESOLVER} = 1;
$r->lookup(
'google.com',
sub {
my ($self, $address) = @_;
$result = $address;
Mojo::IOLoop->stop;
}
);
Mojo::IOLoop->start;
ok !$result, 'got no address';
$ENV{MOJO_NO_RESOLVER} = $backup;

# Lookup again
$result = undef;
$r->lookup(
'google.com',
sub {
my ($self, $address) = @_;
$result = $address;
Mojo::IOLoop->stop;
}
);
Mojo::IOLoop->start;
ok $result, 'got an address';

# Resolve TXT record
$result = undef;
$r->resolve(
Expand Down

0 comments on commit 62057f8

Please sign in to comment.