Skip to content

Commit bad7fdc

Browse files
sylvain-8422pcomandeo-mongo
authored
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 <code@olegp.name> Co-authored-by: Dmitry Rybakov <dmitry.rybakov@mongodb.com>
1 parent 70cb9e4 commit bad7fdc

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

lib/mongo/collection/view/iterable.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def initial_query_op(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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,6 +1790,62 @@
17901790
it 'returns a new View' do
17911791
expect(new_view).not_to be(view)
17921792
end
1793+
1794+
context 'when sending to server' do
1795+
let(:subscriber) { Mrss::EventSubscriber.new }
1796+
1797+
before do
1798+
authorized_collection.client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
1799+
end
1800+
1801+
let(:event) do
1802+
subscriber.single_command_started_event('find')
1803+
end
1804+
1805+
it 'is sent to server' do
1806+
new_view.to_a
1807+
event.command.slice('noCursorTimeout').should == {'noCursorTimeout' => true}
1808+
end
1809+
end
1810+
1811+
context 'integration test' do
1812+
require_topology :single
1813+
1814+
# The number of open cursors with the option set to prevent timeout.
1815+
def current_no_timeout_count
1816+
root_authorized_client
1817+
.command(serverStatus: 1)
1818+
.documents
1819+
.first
1820+
.fetch('metrics')
1821+
.fetch('cursor')
1822+
.fetch('open')
1823+
.fetch('noTimeout')
1824+
end
1825+
1826+
it 'is applied on the server' do
1827+
# Initialize collection with two documents.
1828+
new_view.collection.insert_many([{}, {}])
1829+
1830+
expect(new_view.count).to be == 2
1831+
1832+
# Initial "noTimeout" count should be zero.
1833+
states = [current_no_timeout_count]
1834+
1835+
# The "noTimeout" count should be one while iterating.
1836+
new_view.batch_size(1).each { states << current_no_timeout_count }
1837+
1838+
# Final "noTimeout" count should be back to zero.
1839+
states << current_no_timeout_count
1840+
1841+
# This succeeds on:
1842+
# commit aab776ebdfb15ddb9765039f7300e15796de0c5c
1843+
#
1844+
# This starts failing with [0, 0, 0, 0] from:
1845+
# commit 2d9f0217ec904a1952a1ada2136502eefbca562e
1846+
expect(states).to be == [0, 1, 1, 0]
1847+
end
1848+
end
17931849
end
17941850

17951851
describe '#projection' do

0 commit comments

Comments
 (0)