Skip to content

Commit 007ccac

Browse files
committed
RUBY-1279 Add test for non-exhausted cursor
1 parent 88233e4 commit 007ccac

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

spec/mongo/cluster/cursor_reaper_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,41 @@
143143
end
144144
end
145145
end
146+
147+
context 'when a non-exhausted cursor goes out of scope' do
148+
149+
let(:docs) do
150+
103.times.collect { |i| { a: i } }
151+
end
152+
153+
let(:periodic_executor) do
154+
cluster.instance_variable_get(:@periodic_executor)
155+
end
156+
157+
let(:cluster) do
158+
authorized_client.cluster
159+
end
160+
161+
let(:cursor) do
162+
view = authorized_collection.find
163+
view.to_enum.next
164+
cursor = view.instance_variable_get(:@cursor)
165+
end
166+
167+
around do |example|
168+
authorized_collection.insert_many(docs)
169+
periodic_executor.stop!
170+
cluster.schedule_kill_cursor(cursor.id, cursor.send(:kill_cursors_op_spec),
171+
cursor.instance_variable_get(:@server))
172+
periodic_executor.flush
173+
example.run
174+
periodic_executor.run!
175+
end
176+
177+
it 'schedules the kill cursor op' do
178+
expect {
179+
cursor.to_a
180+
}.to raise_exception(Mongo::Error::OperationFailure)
181+
end
182+
end
146183
end

0 commit comments

Comments
 (0)