spec/arborist/monitor/socket_spec.rb in arborist-0.0.1.pre20160829140603 vs spec/arborist/monitor/socket_spec.rb in arborist-0.0.1.pre20161005112841
- old
+ new
@@ -46,16 +46,15 @@
def make_successful_mock_socket( node )
address = Addrinfo.tcp( node.addresses.first.to_s, node.port )
socket = instance_double( Socket, "#{node.identifier} socket", remote_address: address )
- errors = [ IO::EINPROGRESSWaitWritable, Errno::EISCONN ]
- expect( socket ).to receive( :connect_nonblock ) do |addr|
- expect( addr ).to eq( sockaddr_for(node) )
- raise errors.shift
- end.at_least( :once )
+ expect( socket ).to receive( :connect_nonblock ).with( sockaddr_for(node) ).
+ and_raise( IO::EINPROGRESSWaitWritable )
+ allow( socket ).to receive( :getpeername ).
+ and_return( address.to_sockaddr )
return socket
end
@@ -72,16 +71,17 @@
def make_wait_error_mock_socket( node, error_class, message )
address = Addrinfo.tcp( node.addresses.first.to_s, node.port )
socket = instance_double( Socket, "#{node.identifier} socket", remote_address: address )
- errors = [ IO::EINPROGRESSWaitWritable, error_class.new(message) ]
- expect( socket ).to receive( :connect_nonblock ) do |addr|
- expect( addr ).to eq( sockaddr_for(node) )
- raise errors.shift
- end.at_least( :once )
+ expect( socket ).to receive( :connect_nonblock ).with( sockaddr_for(node) ).
+ and_raise( IO::EINPROGRESSWaitWritable )
+ expect( socket ).to receive( :getpeername ).
+ and_raise( Errno::EINVAL.new("Invalid argument - getpeername(2)") )
+ expect( socket ).to receive( :read ).with( 1 ).
+ and_raise( Errno::ECONNREFUSED.new )
return socket
end
@@ -162,25 +162,9 @@
result = described_class.run( 'test-www' => www_service_node.fetch_values )
expect( result ).to be_a( Hash )
expect( result ).to include( 'test-www' )
expect( result['test-www'] ).to include( error: 'No route to host - the message' )
- end
-
-
- it "updates nodes with an error on a 'getpeername' error" do
- socket = make_wait_error_mock_socket( www_service_node, Errno::EINVAL, "getpeername(2)" )
- allow( Socket ).to receive( :new ).and_return( socket )
- allow( IO ).to receive( :select ).
- with( nil, [socket], nil, kind_of(Numeric) ).
- and_return( [nil, [socket], nil] )
- allow( socket ).to receive( :close )
-
- result = described_class.run( 'test-www' => www_service_node.fetch_values )
-
- expect( result ).to be_a( Hash )
- expect( result ).to include( 'test-www' )
- expect( result['test-www'] ).to include( error: 'Invalid argument - getpeername(2)' )
end
it "can be instantiated to run with a different timeout" do
mon = described_class.new.with_timeout( 30 )