spec/mongo/operation/create/op_msg_spec.rb in mongo-2.20.1 vs spec/mongo/operation/create/op_msg_spec.rb in mongo-2.21.0
- old
+ new
@@ -1,12 +1,16 @@
# frozen_string_literal: true
# rubocop:todo all
require 'spec_helper'
+require_relative '../shared/csot/examples'
describe Mongo::Operation::Create::OpMsg do
+ include CSOT::Examples
+ let(:context) { Mongo::Operation::Context.new }
+
let(:write_concern) do
Mongo::WriteConcern.get(w: :majority)
end
let(:session) { nil }
@@ -71,12 +75,10 @@
end
end
end
describe '#selector' do
- min_server_fcv '3.6'
-
it 'does not mutate user input' do
user_input = IceNine.deep_freeze(spec.dup)
expect do
described_class.new(user_input).send(:selector, connection)
end.not_to raise_error
@@ -85,160 +87,154 @@
describe '#message' do
# https://jira.mongodb.org/browse/RUBY-2224
require_no_linting
- context 'when the server supports OP_MSG' do
+ let(:global_args) do
+ {
+ create: TEST_COLL,
+ writeConcern: write_concern.options,
+ '$db' => SpecConfig.instance.test_db,
+ lsid: session.session_id
+ }
+ end
- let(:global_args) do
- {
- create: TEST_COLL,
- writeConcern: write_concern.options,
- '$db' => SpecConfig.instance.test_db,
- lsid: session.session_id
- }
+ let(:session) do
+ authorized_client.start_session
+ end
+
+ context 'when the topology is replica set or sharded' do
+ require_topology :replica_set, :sharded
+
+ let(:expected_global_args) do
+ global_args.merge(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
end
- let(:session) do
- authorized_client.start_session
+ it 'creates the correct OP_MSG message' do
+ authorized_client.command(ping:1)
+ expect(Mongo::Protocol::Msg).to receive(:new).with([], {}, expected_global_args)
+ op.send(:message, connection)
end
+ end
- context 'when the topology is replica set or sharded' do
- min_server_fcv '3.6'
- require_topology :replica_set, :sharded
+ context 'when the topology is standalone' do
+ require_topology :single
- let(:expected_global_args) do
- global_args.merge(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
- end
+ let(:expected_global_args) do
+ global_args
+ end
- it 'creates the correct OP_MSG message' do
- authorized_client.command(ping:1)
- expect(Mongo::Protocol::Msg).to receive(:new).with([], {}, expected_global_args)
- op.send(:message, connection)
- end
+ it 'creates the correct OP_MSG message' do
+ authorized_client.command(ping:1)
+ expect(Mongo::Protocol::Msg).to receive(:new).with([], {}, expected_global_args)
+ op.send(:message, connection)
end
- context 'when the topology is standalone' do
- min_server_fcv '3.6'
- require_topology :single
+ context 'when an implicit session is created and the topology is then updated and the server does not support sessions' do
+ # Mocks on features are incompatible with linting
+ require_no_linting
let(:expected_global_args) do
- global_args
+ global_args.dup.tap do |args|
+ args.delete(:lsid)
+ end
end
- it 'creates the correct OP_MSG message' do
- authorized_client.command(ping:1)
- expect(Mongo::Protocol::Msg).to receive(:new).with([], {}, expected_global_args)
- op.send(:message, connection)
+ let(:session) do
+ Mongo::Session.new(nil, authorized_client, implicit: true).tap do |session|
+ allow(session).to receive(:session_id).and_return(42)
+ session.should be_implicit
+ end
end
- context 'when an implicit session is created and the topology is then updated and the server does not support sessions' do
- # Mocks on features are incompatible with linting
- require_no_linting
+ it 'creates the correct OP_MSG message' do
+ RSpec::Mocks.with_temporary_scope do
+ expect(connection.features).to receive(:sessions_enabled?).and_return(false)
- let(:expected_global_args) do
- global_args.dup.tap do |args|
- args.delete(:lsid)
- end
+ expect(expected_global_args[:session]).to be nil
+ expect(Mongo::Protocol::Msg).to receive(:new).with([], {}, expected_global_args)
+ op.send(:message, connection)
end
+ end
+ end
+ end
- let(:session) do
- Mongo::Session.new(nil, authorized_client, implicit: true).tap do |session|
- allow(session).to receive(:session_id).and_return(42)
- session.should be_implicit
- end
- end
+ context 'when the write concern is 0' do
- it 'creates the correct OP_MSG message' do
- RSpec::Mocks.with_temporary_scope do
- expect(connection.features).to receive(:sessions_enabled?).and_return(false)
-
- expect(expected_global_args[:session]).to be nil
- expect(Mongo::Protocol::Msg).to receive(:new).with([], {}, expected_global_args)
- op.send(:message, connection)
- end
- end
- end
+ let(:write_concern) do
+ Mongo::WriteConcern.get(w: 0)
end
- context 'when the write concern is 0' do
+ context 'when the session is implicit' do
- let(:write_concern) do
- Mongo::WriteConcern.get(w: 0)
+ let(:session) do
+ Mongo::Session.new(nil, authorized_client, implicit: true).tap do |session|
+ allow(session).to receive(:session_id).and_return(42)
+ session.should be_implicit
+ end
end
- context 'when the session is implicit' do
+ context 'when the topology is replica set or sharded' do
+ require_topology :replica_set, :sharded
- let(:session) do
- Mongo::Session.new(nil, authorized_client, implicit: true).tap do |session|
- allow(session).to receive(:session_id).and_return(42)
- session.should be_implicit
+ let(:expected_global_args) do
+ global_args.dup.tap do |args|
+ args.delete(:lsid)
+ args.merge!(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
end
end
- context 'when the topology is replica set or sharded' do
- min_server_fcv '3.6'
- require_topology :replica_set, :sharded
+ it 'does not send a session id in the command' do
+ authorized_client.command(ping:1)
+ expect(Mongo::Protocol::Msg).to receive(:new).with([:more_to_come], {}, expected_global_args)
+ op.send(:message, connection)
+ end
+ end
- let(:expected_global_args) do
- global_args.dup.tap do |args|
- args.delete(:lsid)
- args.merge!(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
- end
- end
+ context 'when the topology is standalone' do
+ require_topology :single
- it 'does not send a session id in the command' do
- authorized_client.command(ping:1)
- expect(Mongo::Protocol::Msg).to receive(:new).with([:more_to_come], {}, expected_global_args)
- op.send(:message, connection)
+ let(:expected_global_args) do
+ global_args.dup.tap do |args|
+ args.delete(:lsid)
end
end
- context 'when the topology is standalone' do
- min_server_fcv '3.6'
- require_topology :single
-
- let(:expected_global_args) do
- global_args.dup.tap do |args|
- args.delete(:lsid)
- end
- end
-
- it 'creates the correct OP_MSG message' do
- authorized_client.command(ping:1)
- expect(Mongo::Protocol::Msg).to receive(:new).with([:more_to_come], {}, expected_global_args)
- op.send(:message, connection)
- end
+ it 'creates the correct OP_MSG message' do
+ authorized_client.command(ping:1)
+ expect(Mongo::Protocol::Msg).to receive(:new).with([:more_to_come], {}, expected_global_args)
+ op.send(:message, connection)
end
end
+ end
- context 'when the session is explicit' do
- min_server_fcv '3.6'
- require_topology :replica_set, :sharded
+ context 'when the session is explicit' do
+ require_topology :replica_set, :sharded
- let(:session) do
- authorized_client.start_session
- end
+ let(:session) do
+ authorized_client.start_session
+ end
- before do
- session.should_not be_implicit
- end
+ before do
+ session.should_not be_implicit
+ end
- let(:expected_global_args) do
- global_args.dup.tap do |args|
- args.delete(:lsid)
- args.merge!(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
- end
+ let(:expected_global_args) do
+ global_args.dup.tap do |args|
+ args.delete(:lsid)
+ args.merge!(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
end
+ end
- it 'does not send a session id in the command' do
- authorized_client.command(ping:1)
- RSpec::Mocks.with_temporary_scope do
- expect(Mongo::Protocol::Msg).to receive(:new).with([:more_to_come], {}, expected_global_args)
- op.send(:message, connection)
- end
+ it 'does not send a session id in the command' do
+ authorized_client.command(ping:1)
+ RSpec::Mocks.with_temporary_scope do
+ expect(Mongo::Protocol::Msg).to receive(:new).with([:more_to_come], {}, expected_global_args)
+ op.send(:message, connection)
end
end
end
end
end
+
+ it_behaves_like 'a CSOT-compliant OpMsg subclass'
end