This repository was archived by the owner on Dec 7, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ module Celluloid
5
5
module IO
6
6
# Asynchronous DNS resolver using Celluloid::IO::UDPSocket
7
7
class DNSResolver
8
+ class SocketNameResolutionError < SocketError ; end
9
+
8
10
# Maximum UDP packet we'll accept
9
11
MAX_PACKET_SIZE = 512
10
12
DNS_PORT = 53
@@ -29,7 +31,9 @@ def initialize
29
31
30
32
# The non-blocking secret sauce is here, as this is actually a
31
33
# Celluloid::IO::UDPSocket
32
- @socket = UDPSocket . new ( @server . family )
34
+ unless @socket = UDPSocket . new ( @server . family )
35
+ fail SocketNameResolutionError , "nodename nor servname provided, or not known"
36
+ end
33
37
end
34
38
35
39
def resolve ( hostname )
Original file line number Diff line number Diff line change 39
39
expect ( results ) . to be_an_instance_of ( Resolv ::IPv4 )
40
40
end
41
41
end
42
+
43
+ it "raises SocketError if unable to connect to the nameserver" do
44
+ allow ( Celluloid ::IO ::UDPSocket ) . to receive ( :new ) . and_return ( nil )
45
+ expect { Celluloid ::IO ::DNSResolver . new } . to raise_error ( Celluloid ::IO ::DNSResolver ::SocketNameResolutionError )
46
+ end
42
47
end
43
48
end
You can’t perform that action at this time.
0 commit comments