Skip to content

Commit 438fcaa

Browse files
sylvain-8422pcomandeo-mongo
committed
RUBY-3046 send no_cursor_timeout to server again (#2557)
* Mongo::Collection::View#no_cursor_timeout regression * adjust description * add a unit test * pass no cursor timeout option to server * fix test with auth * restrict to standalones Co-authored-by: Oleg Pudeyev <[email protected]> Co-authored-by: Dmitry Rybakov <[email protected]>
1 parent a84f53f commit 438fcaa

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

lib/mongo/collection/view/iterable.rb

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def initial_query_op(server, session)
170170
max_time_ms: options[:max_time_ms],
171171
max_value: options[:max_value],
172172
min_value: options[:min_value],
173+
no_cursor_timeout: options[:no_cursor_timeout],
173174
return_key: options[:return_key],
174175
show_disk_loc: options[:show_disk_loc],
175176
comment: options[:comment],

spec/mongo/collection/view/readable_spec.rb

+56
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,62 @@
11861186
it 'returns a new View' do
11871187
expect(new_view).not_to be(view)
11881188
end
1189+
1190+
context 'when sending to server' do
1191+
let(:subscriber) { Mrss::EventSubscriber.new }
1192+
1193+
before do
1194+
authorized_collection.client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
1195+
end
1196+
1197+
let(:event) do
1198+
subscriber.single_command_started_event('find')
1199+
end
1200+
1201+
it 'is sent to server' do
1202+
new_view.to_a
1203+
event.command.slice('noCursorTimeout').should == {'noCursorTimeout' => true}
1204+
end
1205+
end
1206+
1207+
context 'integration test' do
1208+
require_topology :single
1209+
1210+
# The number of open cursors with the option set to prevent timeout.
1211+
def current_no_timeout_count
1212+
root_authorized_client
1213+
.command(serverStatus: 1)
1214+
.documents
1215+
.first
1216+
.fetch('metrics')
1217+
.fetch('cursor')
1218+
.fetch('open')
1219+
.fetch('noTimeout')
1220+
end
1221+
1222+
it 'is applied on the server' do
1223+
# Initialize collection with two documents.
1224+
new_view.collection.insert_many([{}, {}])
1225+
1226+
expect(new_view.count).to be == 2
1227+
1228+
# Initial "noTimeout" count should be zero.
1229+
states = [current_no_timeout_count]
1230+
1231+
# The "noTimeout" count should be one while iterating.
1232+
new_view.batch_size(1).each { states << current_no_timeout_count }
1233+
1234+
# Final "noTimeout" count should be back to zero.
1235+
states << current_no_timeout_count
1236+
1237+
# This succeeds on:
1238+
# commit aab776ebdfb15ddb9765039f7300e15796de0c5c
1239+
#
1240+
# This starts failing with [0, 0, 0, 0] from:
1241+
# commit 2d9f0217ec904a1952a1ada2136502eefbca562e
1242+
expect(states).to be == [0, 1, 1, 0]
1243+
end
1244+
end
11891245
end
11901246

11911247
describe '#projection' do

0 commit comments

Comments
 (0)