Skip to content

Commit 1d8411d

Browse files
committed
Using comment in the query instead of docs with an object id
1 parent 5ee1dac commit 1d8411d

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

test/replica_set/cursor_test.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ def setup_client(read=:primary)
5151
@db = @client.db(MONGO_TEST_DB)
5252
@db.drop_collection("cursor_tests")
5353
@coll = @db.collection("cursor_tests")
54+
insert_docs
5455

5556
# Setup Direct Connections
5657
@primary = Mongo::MongoClient.new(*@client.manager.primary)
5758
end
5859

5960
def insert_docs
6061
@n_docs = 102 # batch size is 101
61-
@object_id = BSON::ObjectId.new
6262
@n_docs.times do |i|
63-
@coll.insert({ "x" => @object_id }, :w => 3)
63+
@coll.insert({ "x" => i }, :w => 3)
6464
end
6565
end
6666

@@ -84,6 +84,8 @@ def set_read_client_and_tag(read)
8484
def route_query(read)
8585
read_opts = {:read => read}
8686
read_opts[:tag_sets] = [{:node => @tag}] unless read == :primary
87+
object_id = BSON::ObjectId.new
88+
read_opts[:comment] = object_id
8789

8890
# set profiling level to 2 on client and member to which the query will be routed
8991
@client.db(MONGO_TEST_DB).profiling_level = :all
@@ -92,7 +94,7 @@ def route_query(read)
9294
node.db(MONGO_TEST_DB).profiling_level = :all
9395
end
9496

95-
@cursor = @coll.find({"x" => @object_id }, read_opts)
97+
@cursor = @coll.find({}, read_opts)
9698
@cursor.next
9799

98100
# on client and other members set profiling level to 0
@@ -103,7 +105,7 @@ def route_query(read)
103105
end
104106
# do a query on system.profile of the reader to see if it was used for the query
105107
profiled_queries = @read.db(MONGO_TEST_DB).collection('system.profile').find({
106-
'ns' => "#{MONGO_TEST_DB}.cursor_tests", "query.x" => @object_id })
108+
'ns' => "#{MONGO_TEST_DB}.cursor_tests", "query.$comment" => object_id })
107109

108110
assert_equal 1, profiled_queries.count
109111
end
@@ -113,7 +115,6 @@ def route_query(read)
113115
def cursor_get_more_test(read=:primary)
114116
set_read_client_and_tag(read)
115117
10.times do
116-
insert_docs
117118
# assert that the query went to the correct member
118119
route_query(read)
119120
docs_count = 1
@@ -134,7 +135,6 @@ def cursor_get_more_test(read=:primary)
134135
def kill_cursor_test(read=:primary)
135136
set_read_client_and_tag(read)
136137
10.times do
137-
insert_docs
138138
# assert that the query went to the correct member
139139
route_query(read)
140140
cursor_id = @cursor.cursor_id
@@ -153,7 +153,6 @@ def kill_cursor_test(read=:primary)
153153

154154
def assert_cursors_on_members(read=:primary)
155155
set_read_client_and_tag(read)
156-
insert_docs
157156
# assert that the query went to the correct member
158157
route_query(read)
159158
cursor_id = @cursor.cursor_id

0 commit comments

Comments
 (0)