Skip to content

Commit f16aca4

Browse files
committed
Also verify servers are reset to unknown
1 parent 9ad9b2c commit f16aca4

File tree

2 files changed

+41
-17
lines changed

2 files changed

+41
-17
lines changed

spec/integration/retryable_errors_spec.rb

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
describe 'Retryable writes tests' do
44

55
let(:client) do
6-
authorized_client.with(retry_writes: true)
6+
subscribed_client
77
end
88

99
let(:collection) do
@@ -41,9 +41,23 @@
4141
client['retryable-writes-error-spec', read: {mode: :secondary_preferred}]
4242
end
4343

44-
it 'is reported on the server of the second attempt' do
45-
first_primary = client.cluster.next_primary
44+
let(:events) do
45+
events = EventSubscriber.command_started_events('find')
46+
end
47+
48+
let(:first_server) do
49+
client.cluster.servers_list.detect do |server|
50+
server.address.seed == events.first.address.seed
51+
end
52+
end
53+
54+
let(:second_server) do
55+
client.cluster.servers_list.detect do |server|
56+
server.address.seed == events.last.address.seed
57+
end
58+
end
4659

60+
let(:perform_read) do
4761
client.cluster.servers_list.each do |server|
4862
server.monitor.stop!
4963
end
@@ -52,29 +66,32 @@
5266
client.use(:admin).database.command(fail_point_command)
5367
end
5468

55-
# Retry should happen on a server other than the one used for
56-
# initial attempt
57-
expected_hosts = client.cluster.servers.reject do |server|
58-
server.address == first_primary.address
59-
end.map(&:address).map(&:host)
60-
6169
begin
6270
collection.find(a: 1).to_a
63-
rescue Mongo::Error::OperationFailure => e
71+
rescue Mongo::Error::OperationFailure => @exception
6472
else
6573
fail('Expected operation to fail')
6674
end
6775

68-
puts e.message
76+
puts @exception.message
6977

70-
found = expected_hosts.any? do |host|
71-
e.message.include?(host)
72-
end
73-
expect(found).to be true
78+
expect(events.length).to eq(2)
79+
expect(events.first.address.seed).not_to eq(events.last.address.seed)
80+
end
81+
82+
it 'is reported on the server of the second attempt' do
83+
perform_read
84+
85+
expect(@exception.message).not_to include(first_server.address.seed)
86+
expect(@exception.message).to include(second_server.address.seed)
87+
end
88+
89+
it 'marks servers used in both attempts unknown' do
90+
perform_read
7491

75-
expect(e.message).not_to include("on #{first_primary.address.seed}")
92+
expect(first_server).to be_unknown
7693

77-
current_primary = client.cluster.next_primary
94+
expect(second_server).to be_unknown
7895
end
7996
end
8097
end

spec/support/event_subscriber.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ def started(event)
4444
end
4545
end
4646

47+
# Filters command started events for the specified command name.
48+
def command_started_events(command_name)
49+
started_events.select do |event|
50+
event.command[command_name]
51+
end
52+
end
53+
4754
# Locates command stated events for the specified command name,
4855
# asserts that there is exactly one such event, and returns it.
4956
def single_command_started_event(command_name)

0 commit comments

Comments
 (0)