summaryrefslogtreecommitdiff
path: root/test/resolv/test_dns.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-22 08:46:12 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-22 08:46:12 +0000
commit16f4ecbc8cb83f0cadf02eb254623c27ea1946f1 (patch)
tree827e139be8cc22ed62a385a5f58b265bc7cfd5c6 /test/resolv/test_dns.rb
parentf600a558e03976679a9b8e5c24e14bb9c7d70916 (diff)
* lib/resolv.rb: make timeout configurable for DNS query.
patch by Eric Wong. [ruby-core:38533] [Feature #5100] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/resolv/test_dns.rb')
-rw-r--r--test/resolv/test_dns.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/resolv/test_dns.rb b/test/resolv/test_dns.rb
index 9a9c33e..3fce206 100644
--- a/test/resolv/test_dns.rb
+++ b/test/resolv/test_dns.rb
@@ -105,6 +105,30 @@ class TestResolvDNS < Test::Unit::TestCase
}
end
+ def test_query_ipv4_address_timeout
+ with_udp('127.0.0.1', 0) {|u|
+ _, port , _, host = u.addr
+ start = nil
+ rv = Resolv::DNS.open(:nameserver_port => [[host, port]]) {|dns|
+ dns.timeouts = 0.1
+ start = Time.now
+ dns.getresources("foo.example.org", Resolv::DNS::Resource::IN::A)
+ }
+ diff = Time.now - start
+ assert rv.empty?, "unexpected: #{rv.inspect} (expected empty)"
+ assert_in_delta 0.1, diff, 0.05
+
+ rv = Resolv::DNS.open(:nameserver_port => [[host, port]]) {|dns|
+ dns.timeouts = [ 0.1, 0.2 ]
+ start = Time.now
+ dns.getresources("foo.example.org", Resolv::DNS::Resource::IN::A)
+ }
+ diff = Time.now - start
+ assert rv.empty?, "unexpected: #{rv.inspect} (expected empty)"
+ assert_in_delta 0.3, diff, 0.05
+ }
+ end
+
def test_no_server
u = UDPSocket.new
u.bind("127.0.0.1", 0)