Skip to content

Commit 9ad9b2c

Browse files
committed
RUBY-1954 Integration test for exceptions referencing second attempt's server for retryable operations
1 parent 7c0ec22 commit 9ad9b2c

File tree

3 files changed

+93
-12
lines changed

3 files changed

+93
-12
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
require 'spec_helper'
2+
3+
describe 'Retryable writes tests' do
4+
5+
let(:client) do
6+
authorized_client.with(retry_writes: true)
7+
end
8+
9+
let(:collection) do
10+
client['retryable-writes-error-spec']
11+
end
12+
13+
context 'when retry fails' do
14+
require_topology :replica_set
15+
16+
let(:fail_point_command) do
17+
{
18+
configureFailPoint: 'failCommand',
19+
mode: {times: 1},
20+
data: {
21+
failCommands: ['find'],
22+
errorCode: 11600,
23+
},
24+
}
25+
end
26+
27+
let(:clear_fail_point_command) do
28+
{
29+
configureFailPoint: 'failCommand',
30+
mode: 'off',
31+
}
32+
end
33+
34+
after do
35+
ClusterTools.instance.direct_client_for_each_server do |client|
36+
client.use(:admin).database.command(clear_fail_point_command)
37+
end
38+
end
39+
40+
let(:collection) do
41+
client['retryable-writes-error-spec', read: {mode: :secondary_preferred}]
42+
end
43+
44+
it 'is reported on the server of the second attempt' do
45+
first_primary = client.cluster.next_primary
46+
47+
client.cluster.servers_list.each do |server|
48+
server.monitor.stop!
49+
end
50+
51+
ClusterTools.instance.direct_client_for_each_server do |client|
52+
client.use(:admin).database.command(fail_point_command)
53+
end
54+
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+
61+
begin
62+
collection.find(a: 1).to_a
63+
rescue Mongo::Error::OperationFailure => e
64+
else
65+
fail('Expected operation to fail')
66+
end
67+
68+
puts e.message
69+
70+
found = expected_hosts.any? do |host|
71+
e.message.include?(host)
72+
end
73+
expect(found).to be true
74+
75+
expect(e.message).not_to include("on #{first_primary.address.seed}")
76+
77+
current_primary = client.cluster.next_primary
78+
end
79+
end
80+
end
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
require 'spec_helper'
22

33
describe 'Retryable writes errors tests' do
4-
describe 'when the storage engine does not support retryable writes but the server does' do
4+
5+
let(:client) do
6+
authorized_client.with(retry_writes: true)
7+
end
8+
9+
let(:collection) do
10+
client['retryable-writes-error-spec']
11+
end
12+
13+
context 'when the storage engine does not support retryable writes but the server does' do
514
require_mmapv1
615
min_server_fcv '3.6'
716
require_topology :replica_set, :sharded
@@ -10,14 +19,6 @@
1019
collection.delete_many
1120
end
1221

13-
let(:collection) do
14-
client[authorized_collection.name]
15-
end
16-
17-
let(:client) do
18-
authorized_client.with(retry_writes: true)
19-
end
20-
2122
context 'when a retryable write is attempted' do
2223
it 'raises an actionable error message' do
2324
expect {
@@ -27,4 +28,4 @@
2728
end
2829
end
2930
end
30-
end
31+
end

spec/support/cluster_tools.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,6 @@ def close_clients
349349
end
350350
end
351351

352-
private
353-
354352
def each_server(&block)
355353
admin_client.cluster.servers_list.each(&block)
356354
end
@@ -361,6 +359,8 @@ def direct_client_for_each_server(&block)
361359
end
362360
end
363361

362+
private
363+
364364
def reset_server_states
365365
each_server do |server|
366366
server.unknown!

0 commit comments

Comments
 (0)