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_pooled_db.py
50 lines (40 loc) · 1.83 KB
/
test_pooled_db.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
TEST_TIMESTAMP = int(time.time())
class PooledDBTest(test_shunt.MongoTest):
def test_pooled_db(self):
"""
This tests simply verifies that we can grab two different connections from the pool
and use them independantly.
"""
print asyncmongo.__file__
test_shunt.setup()
client = asyncmongo.Client('id1', maxconnections=5, host='127.0.0.1', port=27017, dbname='test')
test_users_collection = client.connection('test_users')
def insert_callback(response, error):
logging.info(response)
assert len(response) == 1
test_shunt.register_called('inserted')
tornado.ioloop.IOLoop.instance().stop()
test_users_collection.insert({"_id" : "record_test.%d" % TEST_TIMESTAMP}, safe=True, callback=insert_callback)
tornado.ioloop.IOLoop.instance().start()
test_shunt.assert_called('inserted')
def pool_callback(response, error):
assert len(response) == 1
test_shunt.register_called('pool1')
if test_shunt.is_called('pool2'):
tornado.ioloop.IOLoop.instance().stop()
def pool_callback2(response, error):
assert len(response) == 1
test_shunt.register_called('pool2')
if test_shunt.is_called('pool1'):
# don't expect 2 finishes second
tornado.ioloop.IOLoop.instance().stop()
test_users_collection.find({}, limit=1, callback=pool_callback)
test_users_collection.find({}, limit=1, callback=pool_callback2)
tornado.ioloop.IOLoop.instance().start()
test_shunt.assert_called('pool1')
test_shunt.assert_called('pool2')