Skip to content

Commit e2e2fe7

Browse files
p-mongop
andcommitted
RUBY-2091 Provide stack trace for ismaster failures in monitor (#1647)
* RUBY-2091 Provide stack trace for ismaster failures in monitor * Look for required text in warnings rather than mandating complete equality Co-authored-by: Oleg Pudeyev <p@users.noreply.github.com>
1 parent 2c2a277 commit e2e2fe7

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

lib/mongo/server/connection.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def handshake!(socket)
322322
raise exc
323323
end
324324
rescue => e
325-
log_warn("Failed to handshake with #{address}: #{e.class}: #{e}")
325+
log_warn("Failed to handshake with #{address}: #{e.class}: #{e}:\n#{e.backtrace[0..5].join("\n")}")
326326
raise
327327
end
328328
end
@@ -379,7 +379,7 @@ def authenticate!(pending_connection)
379379
begin
380380
Auth.get(user).login(pending_connection)
381381
rescue => e
382-
log_warn("Failed to handshake with #{address}: #{e.class}: #{e}")
382+
log_warn("Failed to handshake with #{address}: #{e.class}: #{e}:\n#{e.backtrace[0..5].join("\n")}")
383383
raise
384384
end
385385
end

lib/mongo/server/monitor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def ismaster
204204
connection.ismaster
205205
end
206206
if exc
207-
log_debug("Error running ismaster on #{server.address}: #{exc.class}: #{exc.message}")
207+
log_debug("Error running ismaster on #{server.address}: #{exc.class}: #{exc}:\n#{exc.backtrace[0..5].join("\n")}")
208208
if monitoring.monitoring?
209209
monitoring.failed(
210210
Monitoring::SERVER_HEARTBEAT,

lib/mongo/server/monitor/connection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def handshake!(socket)
232232
log_warn("Asked to handshake with #{address} but there was no app metadata provided")
233233
end
234234
rescue => e
235-
log_warn("Failed to handshake with #{address}: #{e.class}: #{e}")
235+
log_warn("Failed to handshake with #{address}: #{e.class}: #{e}:\n#{e.backtrace[0..5].join("\n")}")
236236
raise
237237
end
238238

spec/mongo/server/connection_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,13 @@ class ConnectionSpecTestException < Exception; end
137137

138138
it 'logs a warning' do
139139
messages = []
140-
# Straightforward expectations are not working here for some reason
141140
expect(Mongo::Logger.logger).to receive(:warn) do |msg|
142141
messages << msg
143142
end
143+
144144
expect(error).not_to be nil
145-
expect(messages).to include(expected_message)
145+
146+
messages.any? { |msg| msg.include?(expected_message) }.should be true
146147
end
147148

148149
end

spec/mongo/server/monitor/connection_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,17 @@
189189

190190
it 'logs a warning' do
191191
expect_any_instance_of(Mongo::Socket).to receive(:write).and_raise(Mongo::Error::SocketError, 'test error')
192-
expect(Mongo::Logger.logger).to receive(:warn).with(expected_message).and_call_original
192+
193+
messages = []
194+
expect(Mongo::Logger.logger).to receive(:warn) do |msg|
195+
messages << msg
196+
end
197+
193198
expect do
194199
monitor.connection.connect!
195200
end.to raise_error(Mongo::Error::SocketError, 'test error')
201+
202+
messages.any? { |msg| msg.include?(expected_message) }.should be true
196203
end
197204
end
198205
end

0 commit comments

Comments
 (0)