Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUBY-3358 Handle nil session is write_worker #2826

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/mongo/retryable/write_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ def write_with_retry(write_concern, ending_transaction: false, context:, &block)
def nro_write_with_retry(write_concern, context:, &block)
session = context.session
server = select_server(cluster, ServerSelector.primary, session)
options = session&.client&.options || {}

if session&.client.options[:retry_writes]
if options[:retry_writes]
begin
server.with_connection(connection_global_id: context.connection_global_id) do |connection|
yield connection, nil, context
Expand Down
39 changes: 39 additions & 0 deletions spec/mongo/retryable/write_worker_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

require 'spec_helper'

describe Mongo::Retryable::WriteWorker do
describe '#nro_write_with_retry' do
context 'when session is nil' do
let(:retryable) do
authorized_client['write_worker_test']
end

let(:write_concern) do
Mongo::WriteConcern.get(w: 0)
end

let(:write_worker) do
described_class.new(retryable)
end

let(:context) do
instance_double(Mongo::Operation::Context).tap do |context|
allow(context).to receive(:session).and_return(nil)
end
end

before do
# We avoid actual execution of the operation to speed up and simplify
# the spec.
allow(write_worker).to receive(:legacy_write_with_retry).and_return(nil)
end

it 'does not raise' do
expect do
write_worker.nro_write_with_retry(write_concern, context: context)
end.not_to raise_error
end
end
end
end
Loading