Skip to content

Commit

Permalink
Add a failing test case around cursors and secondary reads.
Browse files Browse the repository at this point in the history
If we do a secondary read that is large enough to require sending a
GETMORE, and then do another query before the GETMORE, the secondary
connection gets unpinned, and the GETMORE gets sent to the wrong
server, resulting in CURSOR_NOT_FOUND, even though the cursor still
exists on the server that was initially queried.
  • Loading branch information
nelhage committed Nov 18, 2012
1 parent 43cef18 commit d5e8222
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/replica_set/query_test.rb
Expand Up @@ -44,6 +44,27 @@ def test_query
end
end

# Create a large collection and do a secondary query that returns
# enough records to require sending a GETMORE. In between opening
# the cursor and sending the GETMORE, do a :primary query. Confirm
# that the cursor reading from the secondary continues to talk to
# the secondary, rather than trying to read the cursor from the
# primary, where it does not exist.
def test_secondary_getmore
200.times do |i|
@coll.save({:a => i}, :safe => {:w => 3})
end
as = []
# Set an explicit batch size, in case the default ever changes.
@coll.find({}, { :batch_size => 100, :read => :secondary }) do |c|
c.each do |result|
as << result['a']
@coll.find({:a => result['a']}, :read => :primary).map
end
end
assert_equal(as.sort, 0.upto(199).to_a)
end

def benchmark_queries
t1 = Time.now
10000.times { @coll.find_one }
Expand Down

0 comments on commit d5e8222

Please sign in to comment.