Skip to content
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
14 changes: 4 additions & 10 deletions spec/mongo/bulk_write_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1889,32 +1889,26 @@
it_behaves_like 'an operation using a session'
end

context 'when retryable writes are supported', if: (sessions_enabled? && (replica_set? || sharded?)) do
context 'when retryable writes are supported', if: test_sessions? do

let(:client) do
authorized_client.with(heartbeat_frequency: 100, retry_writes: true).tap do |cl|
cl.subscribe(Mongo::Monitoring::COMMAND, subscriber)
end
authorized_client_with_retry_writes
end

let(:collection) do
client[authorized_collection.name]
end

let(:subscriber) do
EventSubscriber.new
end

let!(:result) do
bulk_write.execute
end

let(:first_txn_number) do
subscriber.started_events[-2].command['txnNumber'].instance_variable_get(:@integer)
EventSubscriber.started_events[-2].command['txnNumber'].instance_variable_get(:@integer)
end

let(:second_txn_number) do
subscriber.started_events[-1].command['txnNumber'].instance_variable_get(:@integer)
EventSubscriber.started_events[-1].command['txnNumber'].instance_variable_get(:@integer)
end

it 'inserts the documents' do
Expand Down
13 changes: 6 additions & 7 deletions spec/mongo/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1360,24 +1360,23 @@
end

let(:client) do
# Monitoring subscribers won't be set up when using Client#with, so a new client must be created.
Mongo::Client.new(ADDRESSES, client_options).tap do |cl|
cl.subscribe(Mongo::Monitoring::COMMAND, subscriber)
cl.subscribe(Mongo::Monitoring::COMMAND, EventSubscriber.clear_events!)
end
end

let(:subscriber) do
EventSubscriber.new
end

let(:command) do
subscriber.started_events.find { |c| c.command_name == :listDatabases }.command
EventSubscriber.started_events.find { |c| c.command_name == :listDatabases }.command
end

before do
client.list_databases({}, true)
end

after do
client.close
end

it 'sends the command with the nameOnly flag set to true' do
expect(command[:nameOnly]).to be(true)
end
Expand Down
10 changes: 2 additions & 8 deletions spec/mongo/collection/view/aggregation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,26 +231,20 @@
end

let(:client) do
authorized_client.with(heartbeat_frequency: 100).tap do |cl|
cl.subscribe(Mongo::Monitoring::COMMAND, subscriber)
end
subscribed_client
end

let(:session) do
client.start_session
end

let(:subscriber) do
EventSubscriber.new
end

let(:view) do
Mongo::Collection::View.new(client[TEST_COLL], selector, view_options)
end

let(:command) do
aggregation.explain
subscriber.started_events.find { |c| c.command_name == 'aggregate'}.command
EventSubscriber.started_events.find { |c| c.command_name == 'aggregate'}.command
end

it 'sends the session id' do
Expand Down
10 changes: 2 additions & 8 deletions spec/mongo/collection/view/map_reduce_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,11 @@
end

let(:client) do
authorized_client.with(monitoring: true).tap do |cl|
cl.subscribe(Mongo::Monitoring::COMMAND, subscriber)
end
end

let(:subscriber) do
EventSubscriber.new
subscribed_client
end

let(:find_command) do
subscriber.started_events[-1].command
EventSubscriber.started_events[-1].command
end

before do
Expand Down
2 changes: 1 addition & 1 deletion spec/mongo/collection/view/readable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@

let(:command) do
operation
subscriber.started_events.find { |cmd| cmd.command_name == 'mapreduce' }.command
EventSubscriber.started_events.find { |cmd| cmd.command_name == 'mapreduce' }.command
end

it_behaves_like 'an operation supporting causally consistent reads'
Expand Down
40 changes: 11 additions & 29 deletions spec/mongo/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -900,26 +900,20 @@
end

let(:client) do
authorized_client.with(heartbeat_frequency: 100).tap do |cl|
cl.subscribe(Mongo::Monitoring::COMMAND, subscriber)
end
subscribed_client
end

let(:session) do
client.start_session
end

let(:subscriber) do
EventSubscriber.new
end

let(:view) do
Mongo::Collection::View.new(client[TEST_COLL], selector, view_options)
end

let(:command) do
client[TEST_COLL].find({}, session: session).explain
subscriber.started_events.find { |c| c.command_name == :explain }.command
EventSubscriber.started_events.find { |c| c.command_name == :explain }.command
end

it 'sends the session id' do
Expand All @@ -935,7 +929,7 @@

let(:command) do
operation
subscriber.started_events.find { |cmd| cmd.command_name == 'find' }.command
EventSubscriber.started_events.find { |cmd| cmd.command_name == 'find' }.command
end

it_behaves_like 'an operation supporting causally consistent reads'
Expand Down Expand Up @@ -1205,13 +1199,7 @@ def generate
context 'when the documents are sent with OP_MSG', if: op_msg_enabled? do

let(:client) do
authorized_client.with(heartbeat_frequency: 100).tap do |cl|
cl.subscribe(Mongo::Monitoring::COMMAND, subscriber)
end
end

let(:subscriber) do
EventSubscriber.new
subscribed_client
end

let(:documents) do
Expand All @@ -1227,7 +1215,7 @@ def generate
end

let(:insert_events) do
subscriber.started_events.select { |e| e.command_name == :insert }
EventSubscriber.started_events.select { |e| e.command_name == :insert }
end

it 'sends the documents in one OP_MSG' do
Expand Down Expand Up @@ -1574,7 +1562,7 @@ def generate

let(:command) do
operation
subscriber.started_events.find { |cmd| cmd.command_name == 'aggregate' }.command
EventSubscriber.started_events.find { |cmd| cmd.command_name == 'aggregate' }.command
end

it_behaves_like 'an operation supporting causally consistent reads'
Expand Down Expand Up @@ -1738,7 +1726,7 @@ def generate

let(:command) do
operation
subscriber.started_events.find { |cmd| cmd.command_name == :count }.command
EventSubscriber.started_events.find { |cmd| cmd.command_name == :count }.command
end

it_behaves_like 'an operation supporting causally consistent reads'
Expand Down Expand Up @@ -1852,7 +1840,7 @@ def generate

let(:command) do
operation
subscriber.started_events.find { |cmd| cmd.command_name == :distinct }.command
EventSubscriber.started_events.find { |cmd| cmd.command_name == :distinct }.command
end

it_behaves_like 'an operation supporting causally consistent reads'
Expand Down Expand Up @@ -2344,7 +2332,7 @@ def generate

let(:command) do
operation
subscriber.started_events.find { |cmd| cmd.command_name == :parallelCollectionScan }.command
EventSubscriber.started_events.find { |cmd| cmd.command_name == :parallelCollectionScan }.command
end

it_behaves_like 'an operation supporting causally consistent reads'
Expand Down Expand Up @@ -3486,13 +3474,7 @@ def generate
context 'when the documents are sent with OP_MSG', if: op_msg_enabled? do

let(:client) do
authorized_client.with(heartbeat_frequency: 100).tap do |cl|
cl.subscribe(Mongo::Monitoring::COMMAND, subscriber)
end
end

let(:subscriber) do
EventSubscriber.new
subscribed_client
end

let(:documents) do
Expand All @@ -3509,7 +3491,7 @@ def generate
end

let(:update_events) do
subscriber.started_events.select { |e| e.command_name == :update }
EventSubscriber.started_events.select { |e| e.command_name == :update }
end

it 'sends the documents in one OP_MSG' do
Expand Down
4 changes: 2 additions & 2 deletions spec/mongo/cursor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@
context 'when an implicit session is used', if: sessions_enabled? do

let(:collection) do
authorized_client_with_subscriber[TEST_COLL]
subscribed_client[TEST_COLL]
end

before do
Expand All @@ -354,7 +354,7 @@
end

let(:find_events) do
event_subscriber.started_events.select { |e| e.command_name == "find" }
EventSubscriber.started_events.select { |e| e.command_name == "find" }
end

context 'when all results are retrieved in the first response' do
Expand Down
10 changes: 2 additions & 8 deletions spec/mongo/database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,21 +256,15 @@
end

let(:client) do
authorized_client.with(heartbeat_frequency: 100).tap do |cl|
cl.subscribe(Mongo::Monitoring::COMMAND, subscriber)
end
end

let(:subscriber) do
EventSubscriber.new
subscribed_client
end

it_behaves_like 'an operation using a session'
it_behaves_like 'a failed operation using a session'


let(:full_command) do
subscriber.started_events.find { |cmd| cmd.command_name == :ismaster }.command
EventSubscriber.started_events.find { |cmd| cmd.command_name == :ismaster }.command
end

it 'does not add a afterClusterTime field' do
Expand Down
8 changes: 1 addition & 7 deletions spec/mongo/retryable_writes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@
end

let(:client) do
authorized_client_with_retry_writes.tap do |cl|
cl.subscribe(Mongo::Monitoring::COMMAND, subscriber)
end
end

let(:subscriber) do
EventSubscriber.new
authorized_client_with_retry_writes
end

before do
Expand Down
12 changes: 3 additions & 9 deletions spec/mongo/session/session_pool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,13 @@
end

let(:client) do
authorized_client.with(heartbeat_frequency: 100).tap do |cl|
cl.subscribe(Mongo::Monitoring::COMMAND, subscriber)
end
subscribed_client
end

after do
client.close
end

let(:subscriber) do
EventSubscriber.new
end

context 'when the number of ids is not larger than 10,000' do

before do
Expand All @@ -177,7 +171,7 @@

let(:end_sessions_command) do
pool.end_sessions
subscriber.started_events.find { |c| c.command_name == :endSessions}
EventSubscriber.started_events.find { |c| c.command_name == :endSessions}
end

it 'sends the endSessions command with all the session ids' do
Expand Down Expand Up @@ -216,7 +210,7 @@
end

let(:end_sessions_commands) do
subscriber.started_events.select { |c| c.command_name == :endSessions}
EventSubscriber.started_events.select { |c| c.command_name == :endSessions}
end

it 'sends the command more than once' do
Expand Down
Loading