em-resolv-replace 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/em-dns-resolver.rb +12 -1
- data/lib/em-resolv-replace.rb +2 -14
- data/test/test_em-resolv-replace.rb +21 -9
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.1
|
data/lib/em-dns-resolver.rb
CHANGED
@@ -8,7 +8,12 @@ module EventMachine
|
|
8
8
|
##
|
9
9
|
|
10
10
|
def self.resolve(hostname)
|
11
|
-
|
11
|
+
if ::Resolv::AddressRegex =~ hostname
|
12
|
+
# hostname contains an IP address, nothing to resolve
|
13
|
+
Request.new(nil, hostname)
|
14
|
+
else
|
15
|
+
Request.new(socket, hostname)
|
16
|
+
end
|
12
17
|
end
|
13
18
|
|
14
19
|
def self.socket
|
@@ -110,6 +115,12 @@ module EventMachine
|
|
110
115
|
EM.next_tick { tick }
|
111
116
|
end
|
112
117
|
def tick
|
118
|
+
# @hostname contains an IP address
|
119
|
+
if @socket.nil?
|
120
|
+
succeed [ @hostname ]
|
121
|
+
return
|
122
|
+
end
|
123
|
+
|
113
124
|
# Break early if nothing to do
|
114
125
|
return if @last_send + @retry_interval > Time.now
|
115
126
|
|
data/lib/em-resolv-replace.rb
CHANGED
@@ -6,22 +6,10 @@ require 'resolv-replace'
|
|
6
6
|
require 'em-dns-resolver'
|
7
7
|
require 'fiber'
|
8
8
|
|
9
|
-
#
|
10
|
-
=begin
|
11
|
-
require './em-resolv-replace'
|
12
|
-
EM.run {
|
13
|
-
Fiber.new do
|
14
|
-
p Resolv.getaddresses('localhost')
|
15
|
-
p Resolv.getaddress('localhost')
|
16
|
-
EM.stop
|
17
|
-
end.resume
|
18
|
-
}
|
19
|
-
=end
|
20
9
|
# Now override the override with EM-aware functions
|
21
10
|
class Resolv
|
22
|
-
|
23
11
|
alias :orig_getaddress :getaddress
|
24
|
-
|
12
|
+
|
25
13
|
def getaddress(host)
|
26
14
|
EM.reactor_running? ? em_getaddresses(host)[0] : orig_getaddress(host)
|
27
15
|
end
|
@@ -56,4 +44,4 @@ class Resolv
|
|
56
44
|
end
|
57
45
|
result
|
58
46
|
end
|
59
|
-
end
|
47
|
+
end
|
@@ -2,20 +2,18 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestEmResolvReplace < Test::Unit::TestCase
|
4
4
|
|
5
|
-
IPv4 = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
|
6
|
-
|
7
5
|
should "resolve address without eventmachine" do
|
8
6
|
Resolv.any_instance.expects(:em_getaddress).times(0)
|
9
7
|
|
10
|
-
assert_match
|
8
|
+
assert_match ::Resolv::AddressRegex, Resolv.getaddress('www.google.com')
|
11
9
|
end
|
12
|
-
|
10
|
+
|
13
11
|
should "resolve address with eventmachine" do
|
14
12
|
Resolv.any_instance.expects(:orig_getaddress).times(0)
|
15
13
|
|
16
14
|
EM.run do
|
17
15
|
Fiber.new do
|
18
|
-
assert_match
|
16
|
+
assert_match ::Resolv::AddressRegex, Resolv.getaddress('www.google.com')
|
19
17
|
EM.stop
|
20
18
|
end.resume
|
21
19
|
end
|
@@ -25,16 +23,16 @@ class TestEmResolvReplace < Test::Unit::TestCase
|
|
25
23
|
Resolv.any_instance.expects(:em_getaddress).times(0)
|
26
24
|
|
27
25
|
results = Resolv.getaddresses('www.google.com')
|
28
|
-
assert_match
|
26
|
+
assert_match ::Resolv::AddressRegex, results.first
|
29
27
|
end
|
30
|
-
|
28
|
+
|
31
29
|
should "resolve addresses with eventmachine" do
|
32
30
|
Resolv.any_instance.expects(:orig_getaddresses).times(0)
|
33
31
|
|
34
32
|
EM.run do
|
35
33
|
Fiber.new do
|
36
34
|
results = Resolv.getaddresses('www.google.com')
|
37
|
-
assert_match
|
35
|
+
assert_match ::Resolv::AddressRegex, results.first
|
38
36
|
EM.stop
|
39
37
|
end.resume
|
40
38
|
end
|
@@ -46,7 +44,21 @@ class TestEmResolvReplace < Test::Unit::TestCase
|
|
46
44
|
EM.run do
|
47
45
|
Fiber.new do
|
48
46
|
results = Resolv.getaddresses('localhost')
|
49
|
-
assert (results.first =~
|
47
|
+
assert (results.first =~ ::Resolv::AddressRegex || results.first =~ /::/), "Invalid IP #{results}"
|
48
|
+
EM.stop
|
49
|
+
end.resume
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
should "not try to resolve an IP address" do
|
54
|
+
Resolv.any_instance.expects(:orig_getaddresses).times(0)
|
55
|
+
|
56
|
+
EM.run do
|
57
|
+
Fiber.new do
|
58
|
+
results = Resolv.getaddresses('127.0.0.1') # IPv4
|
59
|
+
assert (results.first == '127.0.0.1')
|
60
|
+
results = Resolv.getaddresses('::1') # IPv6
|
61
|
+
assert (results.first == '::1')
|
50
62
|
EM.stop
|
51
63
|
end.resume
|
52
64
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 1.1.
|
8
|
+
- 1
|
9
|
+
version: 1.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mike Perham
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-08 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|