Skip to content

Commit 8b4bb76

Browse files
p-mongop
andcommitted
RUBY-2446 Fix intermittent SDAM test failures (#2132)
* allow some ismasters to not complete * also allow regular ismasters to be not responded to * allow in-progress heartbeats on pre-4.4 servers * fix the ranges * stop server monitors to avoid races * fix the check again * increase heartbeat interval Co-authored-by: Oleg Pudeyev <oleg@bsdpower.com>
1 parent a761c45 commit 8b4bb76

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

spec/integration/sdam_error_handling_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
new_local_client(SpecConfig.instance.addresses,
2020
SpecConfig.instance.all_test_options.merge(
2121
socket_timeout: 3, connect_timeout: 3,
22+
heartbeat_frequency: 100,
2223
# Uncomment to print all events to stdout:
2324
#sdam_proc: Utils.subscribe_all_sdam_proc(diagnostic_subscriber),
2425
**Utils.disable_retries_client_options)
@@ -28,6 +29,14 @@
2829
let(:server) { client.cluster.next_primary }
2930

3031
shared_examples_for 'marks server unknown' do
32+
before do
33+
server.monitor.stop!
34+
end
35+
36+
after do
37+
client.close
38+
end
39+
3140
it 'marks server unknown' do
3241
expect(server).not_to be_unknown
3342
RSpec::Mocks.with_temporary_scope do
@@ -38,6 +47,14 @@
3847
end
3948

4049
shared_examples_for 'does not mark server unknown' do
50+
before do
51+
server.monitor.stop!
52+
end
53+
54+
after do
55+
client.close
56+
end
57+
4158
it 'does not mark server unknown' do
4259
expect(server).not_to be_unknown
4360
RSpec::Mocks.with_temporary_scope do

spec/integration/sdam_events_spec.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
succeeded_events = subscriber.select_succeeded_events(Mongo::Monitoring::Event::ServerHeartbeatSucceeded)
7070
# Since we gracefully close the client, we expect each heartbeat
7171
# to complete.
72-
started_events.length.should == succeeded_events.length
72+
started_events.length.should > 1
73+
(succeeded_events.length-1..succeeded_events.length).should include(started_events.length)
7374
end
7475
end
7576

@@ -105,10 +106,12 @@
105106
(succeeded_awaited = events.select(&:awaited?)).should_not be_empty
106107
(succeeded_regular = events.reject(&:awaited?)).should_not be_empty
107108

108-
# Since we gracefully close the client, we expect each heartbeat
109-
# to complete.
110-
started_awaited.length.should == succeeded_awaited.length
111-
started_regular.length.should == succeeded_regular.length
109+
# There may be in-flight ismasters that don't complete, both
110+
# regular and awaited.
111+
started_awaited.length.should > 1
112+
(succeeded_awaited.length-1..succeeded_awaited.length).should include(started_awaited.length)
113+
started_regular.length.should > 1
114+
(succeeded_regular.length-1..succeeded_regular.length).should include(started_regular.length)
112115
end
113116
end
114117
end

0 commit comments

Comments
 (0)