spec/support/shared/session.rb in mongo-2.6.4 vs spec/support/shared/session.rb in mongo-2.7.0.rc0

- old
+ new

@@ -1,8 +1,10 @@ shared_examples 'an operation using a session' do - describe 'operation execution', if: test_sessions? do + describe 'operation execution' do + min_server_version '3.6' + require_topology :replica_set, :sharded context 'when the session is created from the same client used for the operation' do let(:session) do client.start_session @@ -42,11 +44,11 @@ end context 'when a session from another client is provided' do let(:session) do - authorized_client_with_retry_writes.start_session + another_authorized_client.start_session end let(:operation_result) do operation end @@ -81,11 +83,13 @@ end end shared_examples 'a failed operation using a session' do - context 'when the operation fails', if: test_sessions? do + context 'when the operation fails' do + min_server_version '3.6' + require_topology :replica_set, :sharded let!(:before_last_use) do session.instance_variable_get(:@server_session).last_use end @@ -260,11 +264,13 @@ end end end end - context 'when connected to replica set or sharded cluster', if: test_sessions? do + context 'when connected to replica set or sharded cluster' do + min_server_version '3.6' + require_topology :replica_set, :sharded context 'when the collection specifies a read concern' do let(:collection) do client[TEST_COLL, read_concern: { level: 'majority' }] @@ -604,76 +610,89 @@ let(:client) do subscribed_client end + shared_examples_for 'does not update the cluster time of the cluster' do + it 'does not update the cluster time of the cluster' do + bct = before_cluster_time + reply_cluster_time + expect(client.cluster.cluster_time).to eq(before_cluster_time) + end + end + context 'when the command is run once' do context 'when the server is version 3.6' do + min_server_version '3.6' - context 'when the cluster is sharded or a replica set', if: test_sessions? do + context 'when the cluster is sharded or a replica set' do + require_topology :replica_set, :sharded - let!(:reply_cluster_time) do + let(:reply_cluster_time) do operation_with_session EventSubscriber.succeeded_events[-1].reply['$clusterTime'] end it 'updates the cluster time of the cluster' do - expect(cluster.cluster_time).to eq(reply_cluster_time) + rct = reply_cluster_time + expect(cluster.cluster_time).to eq(rct) end it 'updates the cluster time of the session' do - expect(session.cluster_time).to eq(reply_cluster_time) + rct = reply_cluster_time + expect(session.cluster_time).to eq(rct) end end - context 'when the server is a standalone', if: (standalone? && sessions_enabled?) do + context 'when the server is a standalone' do + require_topology :single let(:before_cluster_time) do client.cluster.cluster_time end let!(:reply_cluster_time) do operation_with_session EventSubscriber.succeeded_events[-1].reply['$clusterTime'] end - it 'does not update the cluster time of the cluster' do - expect(before_cluster_time).to eq(before_cluster_time) - end + it_behaves_like 'does not update the cluster time of the cluster' it 'does not update the cluster time of the session' do + reply_cluster_time expect(session.cluster_time).to be_nil end end end - context 'when the server is less than version 3.6', if: !sessions_enabled? do + context 'when the server is less than version 3.6' do + max_server_version '3.4' let(:before_cluster_time) do client.cluster.cluster_time end - let!(:reply_cluster_time) do + let(:reply_cluster_time) do operation EventSubscriber.succeeded_events[-1].reply['$clusterTime'] end - it 'does not update the cluster time of the cluster' do - expect(before_cluster_time).to eq(before_cluster_time) - 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 + let(:reply_cluster_time) do operation_with_session EventSubscriber.succeeded_events[-1].reply['$clusterTime'] end - context 'when the cluster is sharded or a replica set', if: test_sessions? do + context 'when the cluster is sharded or a replica set' do + min_server_version '3.6' + require_topology :replica_set, :sharded context 'when the session cluster time is advanced' do before do session.advance_cluster_time(advanced_cluster_time) @@ -719,10 +738,11 @@ second_operation EventSubscriber.started_events[-1].command['$clusterTime'] end it 'includes the received cluster time in the second command' do + reply_cluster_time expect(second_command_cluster_time).to eq(reply_cluster_time) end end end @@ -736,12 +756,13 @@ second_operation EventSubscriber.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 - expect(before_cluster_time).to eq(before_cluster_time) + expect(client.cluster.cluster_time).to eq(bct) end end end context 'when the server is less than version 3.6', if: !sessions_enabled? do @@ -749,12 +770,13 @@ let(:before_cluster_time) do client.cluster.cluster_time end it 'does not update the cluster time of the cluster' do + bct = before_cluster_time operation - expect(before_cluster_time).to eq(before_cluster_time) + expect(client.cluster.cluster_time).to eq(bct) end end end shared_examples 'an operation not using a session' do @@ -819,10 +841,10 @@ end it 'does not raise an exception' do expect { operation_result - }.not_to raise_exception(Mongo::Error::InvalidSession) + }.not_to raise_exception end end end end