Skip to content

Commit cdc8fc0

Browse files
committed
1588
1 parent 2555d57 commit cdc8fc0

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

lib/mongo/server/round_trip_time_averager.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,15 @@ def measure
3636
rv = yield
3737
rescue Exception => exc
3838
end
39-
@last_round_trip_time = Time.now - start
39+
last_round_trip_time = Time.now - start
4040

41-
update_average_round_trip_time
41+
# If ismaster fails, we need to return the last round trip time
42+
# because it is used in the heartbeat failed SDAM event,
43+
# but we must not update the round trip time recorded in the server.
44+
unless exc
45+
@last_round_trip_time = last_round_trip_time
46+
update_average_round_trip_time
47+
end
4248

4349
[rv, exc, last_round_trip_time, average_round_trip_time]
4450
end

spec/mongo/server/round_trip_time_averager_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,23 @@
2121
end
2222
end
2323
end
24+
25+
describe '#measure' do
26+
context 'block does not raise' do
27+
it 'updates average rtt' do
28+
expect(averager).to receive(:update_average_round_trip_time)
29+
averager.measure do
30+
end
31+
end
32+
end
33+
34+
context 'block raises' do
35+
it 'does not update average rtt' do
36+
expect(averager).not_to receive(:update_average_round_trip_time)
37+
averager.measure do
38+
raise "Problem"
39+
end
40+
end
41+
end
42+
end
2443
end

0 commit comments

Comments
 (0)