spec/mongo/operation/delete/op_msg_spec.rb in mongo-2.6.4 vs spec/mongo/operation/delete/op_msg_spec.rb in mongo-2.7.0.rc0

- old
+ new

@@ -1,11 +1,11 @@ require 'spec_helper' describe Mongo::Operation::Delete::OpMsg do let(:write_concern) do - Mongo::WriteConcern.get(WRITE_CONCERN) + Mongo::WriteConcern.get(SpecConfig.instance.write_concern) end let(:session) { nil } let(:deletes) { [{:q => { :foo => 1 }, :limit => 1}] } let(:spec) do @@ -93,11 +93,11 @@ let(:global_args) do { delete: TEST_COLL, ordered: true, writeConcern: write_concern.options, - '$db' => TEST_DB, + '$db' => SpecConfig.instance.test_db, lsid: session.session_id } end let(:expected_payload_1) do @@ -111,50 +111,56 @@ let(:session) do authorized_client.start_session end - context 'when the topology is replica set or sharded', if: (replica_set? || sharded?) && op_msg_enabled? do + context 'when the topology is replica set or sharded', if: (replica_set? || sharded?) do + min_server_version '3.6' let(:expected_global_args) do global_args.merge(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time) end it 'creates the correct OP_MSG message' do authorized_client.command(ping:1) - expect(Mongo::Protocol::Msg).to receive(:new).with([:none], {}, expected_global_args, expected_payload_1) + expect(Mongo::Protocol::Msg).to receive(:new).with([], {}, expected_global_args, expected_payload_1) op.send(:message, authorized_primary) end end - context 'when the topology is standalone', if: standalone? && op_msg_enabled? do + context 'when the topology is standalone', if: standalone? do + min_server_version '3.6' 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([:none], {}, expected_global_args, expected_payload_1) + expect(Mongo::Protocol::Msg).to receive(:new).with([], {}, expected_global_args, expected_payload_1) op.send(:message, authorized_primary) end context 'when an implicit session is created and the topology is then updated and the server does not support sessions' do let(:expected_global_args) do - global_args.delete(:lsid) - global_args + global_args.dup.tap do |args| + args.delete(:lsid) + end end before do session.instance_variable_set(:@options, { implicit: true }) + # Topology is standalone, hence there is exactly one server + authorized_client.cluster.servers.first.monitor.stop!(true) allow(authorized_primary.features).to receive(:sessions_enabled?).and_return(false) end it 'creates the correct OP_MSG message' do authorized_client.command(ping:1) - expect(Mongo::Protocol::Msg).to receive(:new).with([:none], {}, expected_global_args, expected_payload_1) + expect(expected_global_args[:session]).to be nil + expect(Mongo::Protocol::Msg).to receive(:new).with([], {}, expected_global_args, expected_payload_1) op.send(:message, authorized_primary) end end end @@ -169,15 +175,19 @@ let(:session) do # Use client#get_session so the session is implicit authorized_client.send(:get_session) end - context 'when the topology is replica set or sharded', if: test_sessions? do + context 'when the topology is replica set or sharded' do + min_server_version '3.6' + require_topology :replica_set, :sharded let(:expected_global_args) do - global_args.delete(:lsid) - global_args.merge!(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time) + 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) expect(Mongo::Protocol::Msg).to receive(:new).with([:more_to_come], {}, expected_global_args, expected_payload_1) @@ -186,30 +196,35 @@ end context 'when the topology is standalone', if: standalone? && sessions_enabled? do let(:expected_global_args) do - global_args.delete(:lsid) - 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([:more_to_come], {}, expected_global_args, expected_payload_1) op.send(:message, authorized_primary) end end end - context 'when the session is explicit', if: test_sessions? do + context 'when the session is explicit' do + min_server_version '3.6' + require_topology :replica_set, :sharded let(:session) do authorized_client.start_session end let(:expected_global_args) do - global_args.delete(:lsid) - global_args.merge!(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time) + 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) expect(Mongo::Protocol::Msg).to receive(:new).with([:more_to_come], {}, expected_global_args, expected_payload_1)