Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 44 lines (35 sloc) 2.033 kb
f38d658 @jehiah handle safe=False, set safe=True as default, make safe=False mutually ex...
jehiah authored
1 import tornado.ioloop
2 import time
3 import logging
4
5 import test_shunt
6 import asyncmongo
7
8 TEST_TIMESTAMP = int(time.time())
9
d27388f @jehiah update test code to init/teardown a mongod instance appropriately
jehiah authored
10 class SafeUpdatesTest(test_shunt.MongoTest):
11 def test_update_safe(self):
12 test_shunt.setup()
b6a25cf @jehiah run mongod on non std port for less conflicts
jehiah authored
13 db = asyncmongo.Client(pool_id='testinsert', host='127.0.0.1', port=27018, dbname='test', maxconnections=2)
d27388f @jehiah update test code to init/teardown a mongod instance appropriately
jehiah authored
14
15 def update_callback(response, error):
07e56f0 @ajdavis Harden the unittests a little: close connections between tests, and stop...
ajdavis authored
16 tornado.ioloop.IOLoop.instance().stop()
d27388f @jehiah update test code to init/teardown a mongod instance appropriately
jehiah authored
17 logging.info(response)
18 assert len(response) == 1
19 test_shunt.register_called('update')
07e56f0 @ajdavis Harden the unittests a little: close connections between tests, and stop...
ajdavis authored
20
d27388f @jehiah update test code to init/teardown a mongod instance appropriately
jehiah authored
21 # all of these should be called, but only one should have a callback
22 # we also are checking that connections in the pool never increases >1 with max_connections=2
23 # this is because connections for safe=False calls get put back in the pool immediated
24 db.test_stats.update({"_id" : TEST_TIMESTAMP}, {'$inc' : {'test_count' : 1}}, safe=False, upsert=True)
25 db.test_stats.update({"_id" : TEST_TIMESTAMP}, {'$inc' : {'test_count' : 1}}, safe=False, upsert=True)
26 db.test_stats.update({"_id" : TEST_TIMESTAMP}, {'$inc' : {'test_count' : 1}}, safe=False, upsert=True)
27 db.test_stats.update({"_id" : TEST_TIMESTAMP}, {'$inc' : {'test_count' : 1}}, safe=False, upsert=True)
28 db.test_stats.update({"_id" : TEST_TIMESTAMP}, {'$inc' : {'test_count' : 1}}, upsert=True, callback=update_callback)
29
30 tornado.ioloop.IOLoop.instance().start()
31 test_shunt.assert_called('update')
32
33 def query_callback(response, error):
07e56f0 @ajdavis Harden the unittests a little: close connections between tests, and stop...
ajdavis authored
34 tornado.ioloop.IOLoop.instance().stop()
d27388f @jehiah update test code to init/teardown a mongod instance appropriately
jehiah authored
35 logging.info(response)
36 assert isinstance(response, dict)
37 assert response['_id'] == TEST_TIMESTAMP
38 assert response['test_count'] == 5
39 test_shunt.register_called('retrieved')
07e56f0 @ajdavis Harden the unittests a little: close connections between tests, and stop...
ajdavis authored
40
d27388f @jehiah update test code to init/teardown a mongod instance appropriately
jehiah authored
41 db.test_stats.find_one({"_id" : TEST_TIMESTAMP}, callback=query_callback)
42 tornado.ioloop.IOLoop.instance().start()
43 test_shunt.assert_called('retrieved')
Something went wrong with that request. Please try again.