Skip to content
Browse files

increase verbosity of socket connector to gain visibility into slowne…

…ss of process start up

Signed-off-by: dmitriy kalinin <dmitriy@pivotallabs.com>
  • Loading branch information...
1 parent f97c1be commit bbb21bdd90249c9afd5bbb85b49f615ec7564e70 caleb miles committed
View
3 bosh-dev/lib/bosh/dev/sandbox/socket_connector.rb
@@ -13,8 +13,9 @@ def initialize(host, port, logger)
def try_to_connect(remaining_attempts = 40)
remaining_attempts -= 1
Timeout.timeout(1) { TCPSocket.new(@host, @port).close }
- rescue Timeout::Error, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ETIMEDOUT
+ rescue Timeout::Error, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ETIMEDOUT => e
raise if remaining_attempts == 0
+ @logger.info("Failed to connect: #{e.inspect} host=#{@host} port=#{@port} remaining_attempts=#{remaining_attempts}")
sleep(0.2) # unfortunate fine-tuning required here
retry
end
View
10 bosh-dev/spec/bosh/dev/sandbox/socket_connector_spec.rb
@@ -1,27 +1,25 @@
require 'spec_helper'
+require 'logger'
require 'bosh/dev/sandbox/socket_connector'
module Bosh::Dev::Sandbox
describe SocketConnector do
- let(:socket_connector) { SocketConnector.new('fake host', 'fake port', 'fake logger') }
+ let(:socket_connector) { SocketConnector.new('fake host', 'fake port', logger) }
+ let(:logger) { Logger.new('/dev/null') }
- before do
- Timeout.stub(:timeout).and_raise(Timeout::Error, 'Timeout error')
- end
+ before { Timeout.stub(:timeout).and_raise(Timeout::Error, 'Timeout error') }
describe '#try_to_connect' do
it 'sleeps after each failed attempt then raises' do
Timeout.should_receive(:timeout).ordered
socket_connector.should_receive(:sleep).with(0.2).ordered
Timeout.should_receive(:timeout).ordered
-
expect { socket_connector.try_to_connect(2) }.to raise_error(Timeout::Error, 'Timeout error')
end
it 'defaults to 40 attempts before raising' do
Timeout.should_receive(:timeout).exactly(40).times
socket_connector.should_receive(:sleep).exactly(39).times
-
expect { socket_connector.try_to_connect }.to raise_error(Timeout::Error, 'Timeout error')
end
end

0 comments on commit bbb21bd

Please sign in to comment.
Something went wrong with that request. Please try again.