spec/support/shared/session.rb in mongo-2.12.4 vs spec/support/shared/session.rb in mongo-2.13.0.beta1

- old
+ new

@@ -121,24 +121,22 @@ end end shared_examples 'an explicit session with an unacknowledged write' do - before do - EventSubscriber.clear_events! - end - context 'when sessions are supported' do min_server_fcv '3.6' let(:session) do client.start_session end it 'does not add a session id to the operation' do + subscriber.clear_events! operation - expect(EventSubscriber.started_events.collect(&:command).collect { |cmd| cmd['lsid'] }.compact).to be_empty + subscriber.non_auth_command_started_events.length.should == 1 + expect(subscriber.non_auth_command_started_events.collect(&:command).collect { |cmd| cmd['lsid'] }.compact).to be_empty end end context 'when sessions are not supported' do max_server_version '3.4' @@ -147,45 +145,51 @@ nil end it 'does not add a session id to the operation' do expect(Mongo::Session).not_to receive(:new) + subscriber.clear_events! operation - expect(EventSubscriber.started_events.collect(&:command).collect { |cmd| cmd['lsid'] }.compact).to be_empty + subscriber.non_auth_command_started_events.length.should == 1 + expect(subscriber.non_auth_command_started_events.collect(&:command).collect { |cmd| cmd['lsid'] }.compact).to be_empty end end end shared_examples 'an implicit session with an unacknowledged write' do - before do - EventSubscriber.clear_events! - end - context 'when sessions are supported' do min_server_fcv '3.6' it 'does not add a session id to the operation' do + subscriber.clear_events! operation - expect(EventSubscriber.started_events.collect(&:command).collect { |cmd| cmd['lsid'] }.compact).to be_empty + subscriber.non_auth_command_started_events.length.should == 1 + expect(subscriber.non_auth_command_started_events.collect(&:command).collect { |cmd| cmd['lsid'] }.compact).to be_empty end end context 'when sessions are not supported' do max_server_version '3.4' it 'does not add a session id to the operation' do + subscriber.clear_events! operation - expect(EventSubscriber.started_events.collect(&:command).collect { |cmd| cmd['lsid'] }.compact).to be_empty + subscriber.non_auth_command_started_events.length.should == 1 + expect(subscriber.non_auth_command_started_events.collect(&:command).collect { |cmd| cmd['lsid'] }.compact).to be_empty end end end shared_examples 'an operation supporting causally consistent reads' do + let(:subscriber) { EventSubscriber.new } + let(:client) do - subscribed_client + authorized_client.tap do |client| + client.subscribe(Mongo::Monitoring::COMMAND, subscriber) + end end context 'when connected to a standalone' do min_server_fcv '3.6' require_topology :single @@ -613,12 +617,16 @@ let(:session) do client.start_session end + let(:subscriber) { EventSubscriber.new } + let(:client) do - subscribed_client + authorized_client.tap do |client| + client.subscribe(Mongo::Monitoring::COMMAND, subscriber) + end end shared_examples_for 'does not update the cluster time of the cluster' do it 'does not update the cluster time of the cluster', retry: 3 do bct = before_cluster_time @@ -635,11 +643,11 @@ context 'when the cluster is sharded or a replica set' do require_topology :replica_set, :sharded let(:reply_cluster_time) do operation_with_session - EventSubscriber.succeeded_events[-1].reply['$clusterTime'] + subscriber.succeeded_events[-1].reply['$clusterTime'] end it 'updates the cluster time of the cluster', retry: 3 do rct = reply_cluster_time expect(cluster.cluster_time).to eq(rct) @@ -658,11 +666,11 @@ client.cluster.cluster_time end let!(:reply_cluster_time) do operation_with_session - EventSubscriber.succeeded_events[-1].reply['$clusterTime'] + subscriber.succeeded_events[-1].reply['$clusterTime'] end it_behaves_like 'does not update the cluster time of the cluster' it 'does not update the cluster time of the session', retry: 3 do @@ -679,22 +687,22 @@ client.cluster.cluster_time end let(:reply_cluster_time) do operation - EventSubscriber.succeeded_events[-1].reply['$clusterTime'] + subscriber.succeeded_events[-1].reply['$clusterTime'] end it_behaves_like 'does not update the cluster time of the cluster' end end context 'when the command is run twice' do let(:reply_cluster_time) do operation_with_session - EventSubscriber.succeeded_events[-1].reply['$clusterTime'] + subscriber.succeeded_events[-1].reply['$clusterTime'] end context 'when the cluster is sharded or a replica set' do min_server_fcv '3.6' require_topology :replica_set, :sharded @@ -705,11 +713,11 @@ session.advance_cluster_time(advanced_cluster_time) end let(:second_command_cluster_time) do second_operation - EventSubscriber.started_events[-1].command['$clusterTime'] + subscriber.non_auth_command_started_events[-1].command['$clusterTime'] end context 'when the advanced cluster time is greater than the existing cluster time' do let(:advanced_cluster_time) do @@ -743,11 +751,11 @@ context 'when the session cluster time is not advanced' do let(:second_command_cluster_time) do second_operation - EventSubscriber.started_events[-1].command['$clusterTime'] + subscriber.non_auth_command_started_events[-1].command['$clusterTime'] end it 'includes the received cluster time in the second command', retry: 3 do reply_cluster_time expect(second_command_cluster_time).to eq(reply_cluster_time) @@ -763,10 +771,10 @@ client.cluster.cluster_time end let(:second_command_cluster_time) do second_operation - EventSubscriber.started_events[-1].command['$clusterTime'] + subscriber.non_auth_command_started_events[-1].command['$clusterTime'] end it 'does not update the cluster time of the cluster' do bct = before_cluster_time second_command_cluster_time