Skip to content

RUBY-3046 send no_cursor_timeout to server again #2557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 18, 2022
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
1 change: 1 addition & 0 deletions lib/mongo/collection/view/iterable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def initial_query_op(session)
max_time_ms: options[:max_time_ms],
max_value: options[:max_value],
min_value: options[:min_value],
no_cursor_timeout: options[:no_cursor_timeout],
return_key: options[:return_key],
show_disk_loc: options[:show_disk_loc],
comment: options[:comment],
Expand Down
56 changes: 56 additions & 0 deletions spec/mongo/collection/view/readable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,62 @@
it 'returns a new View' do
expect(new_view).not_to be(view)
end

context 'when sending to server' do
let(:subscriber) { Mrss::EventSubscriber.new }

before do
authorized_collection.client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
end

let(:event) do
subscriber.single_command_started_event('find')
end

it 'is sent to server' do
new_view.to_a
event.command.slice('noCursorTimeout').should == {'noCursorTimeout' => true}
end
end

context 'integration test' do
require_topology :single

# The number of open cursors with the option set to prevent timeout.
def current_no_timeout_count
root_authorized_client
.command(serverStatus: 1)
.documents
.first
.fetch('metrics')
.fetch('cursor')
.fetch('open')
.fetch('noTimeout')
end

it 'is applied on the server' do
# Initialize collection with two documents.
new_view.collection.insert_many([{}, {}])

expect(new_view.count).to be == 2

# Initial "noTimeout" count should be zero.
states = [current_no_timeout_count]

# The "noTimeout" count should be one while iterating.
new_view.batch_size(1).each { states << current_no_timeout_count }

# Final "noTimeout" count should be back to zero.
states << current_no_timeout_count

# This succeeds on:
# commit aab776ebdfb15ddb9765039f7300e15796de0c5c
#
# This starts failing with [0, 0, 0, 0] from:
# commit 2d9f0217ec904a1952a1ada2136502eefbca562e
expect(states).to be == [0, 1, 1, 0]
end
end
end

describe '#projection' do
Expand Down