Skip to content

Commit eed9a97

Browse files
authored
Fix RUBY-1876 cannot disable retryable reads/writes via URI options (#1436)
1 parent 7050c6d commit eed9a97

File tree

2 files changed

+53
-7
lines changed

2 files changed

+53
-7
lines changed

lib/mongo/client.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,6 @@ def initialize(addresses_or_uri, options = nil)
356356
options = {}
357357
end
358358

359-
unless options[:retry_reads] == false
360-
options[:retry_reads] = true
361-
end
362-
unless options[:retry_writes] == false
363-
options[:retry_writes] = true
364-
end
365-
366359
if addresses_or_uri.is_a?(::String)
367360
uri = URI.get(addresses_or_uri, options)
368361
addresses = uri.servers
@@ -379,6 +372,13 @@ def initialize(addresses_or_uri, options = nil)
379372
addresses = addresses_or_uri
380373
end
381374

375+
unless options[:retry_reads] == false
376+
options[:retry_reads] = true
377+
end
378+
unless options[:retry_writes] == false
379+
options[:retry_writes] = true
380+
end
381+
382382
# Special handling for sdam_proc as it is only used during client
383383
# construction
384384
sdam_proc = options.delete(:sdam_proc)

spec/mongo/client_construction_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,52 @@
742742
end
743743
end
744744
end
745+
746+
context 'when retryReads URI option is given' do
747+
748+
context 'it is false' do
749+
let!(:uri) do
750+
'mongodb://127.0.0.1:27017/testdb?retryReads=false'
751+
end
752+
753+
it 'sets the option on the client' do
754+
expect(client.options[:retry_reads]).to be false
755+
end
756+
end
757+
758+
context 'it is true' do
759+
let!(:uri) do
760+
'mongodb://127.0.0.1:27017/testdb?retryReads=true'
761+
end
762+
763+
it 'sets the option on the client' do
764+
expect(client.options[:retry_reads]).to be true
765+
end
766+
end
767+
end
768+
769+
context 'when retryWrites URI option is given' do
770+
771+
context 'it is false' do
772+
let!(:uri) do
773+
'mongodb://127.0.0.1:27017/testdb?retryWrites=false'
774+
end
775+
776+
it 'sets the option on the client' do
777+
expect(client.options[:retry_writes]).to be false
778+
end
779+
end
780+
781+
context 'it is true' do
782+
let!(:uri) do
783+
'mongodb://127.0.0.1:27017/testdb?retryWrites=true'
784+
end
785+
786+
it 'sets the option on the client' do
787+
expect(client.options[:retry_writes]).to be true
788+
end
789+
end
790+
end
745791
end
746792

747793
context 'when options are provided not in the string' do

0 commit comments

Comments
 (0)