This repository has been archived by the owner on Nov 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
/
test_query.py
50 lines (38 loc) · 1.59 KB
/
test_query.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import tornado.ioloop
import logging
import time
import test_shunt
import asyncmongo
import pymongo
class QueryTest(test_shunt.MongoTest):
mongod_options = [('--port', '27017')]
@property
def pymongo_conn(self):
if not hasattr(self, '_pymongo_conn'):
self._pymongo_conn = pymongo.Connection(port=int(self.mongod_options[0][1]))
return self._pymongo_conn
def get_open_cursors(self):
output = self.pymongo_conn.admin.command('serverStatus')
return output.get('cursors', {}).get('totalOpen')
def setUp(self):
super(QueryTest, self).setUp()
self.pymongo_conn.test.foo.insert([{'i': i} for i in xrange(200)])
def test_query(self):
db = asyncmongo.Client(pool_id='test_query', host='127.0.0.1', port=int(self.mongod_options[0][1]), dbname='test', mincached=3)
def noop_callback(response, error):
logging.info(response)
loop = tornado.ioloop.IOLoop.instance()
# delay the stop so kill cursor has time on the ioloop to get pushed through to mongo
loop.add_timeout(time.time() + .1, loop.stop)
before = self.get_open_cursors()
# run 2 queries
db.foo.find({}, callback=noop_callback)
tornado.ioloop.IOLoop.instance().start()
db.foo.find({}, callback=noop_callback)
tornado.ioloop.IOLoop.instance().start()
# check cursors
after = self.get_open_cursors()
assert before == after, "%d cursors left open (should be 0)" % (after - before)
if __name__ == '__main__':
import unittest
unittest.main()