Disable the pymongo pooling feature for tests
Because pymongo doesn't close connection on .close() when we use its pool, we disable the MongoClient pooling feature for running tests. This allow to use a normal number of connection in mongod for test. Fixes bug #1218488 Change-Id: Ie4c74620937816ed0592f5ac72de99dee3173ad8
This commit is contained in:
parent
27937c395d
commit
2152627f1a
@ -22,6 +22,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
import urlparse
|
||||||
import weakref
|
import weakref
|
||||||
|
|
||||||
import bson.code
|
import bson.code
|
||||||
@ -142,9 +143,15 @@ class ConnectionPool(object):
|
|||||||
if client:
|
if client:
|
||||||
return client
|
return client
|
||||||
LOG.info('connecting to DB2 on %s', url)
|
LOG.info('connecting to DB2 on %s', url)
|
||||||
client = pymongo.MongoClient(
|
url_parsed = urlparse.urlparse(url)
|
||||||
url,
|
if url_parsed.path.startswith('/ceilometer_for_tox_testing_'):
|
||||||
safe=True)
|
#note(sileht): this is a workaround for running tests without reach
|
||||||
|
#the maximum allowed connection of mongod in gate
|
||||||
|
#this only work with pymongo >= 2.6, this is not in the
|
||||||
|
#requirements file because is not needed for normal use of mongo
|
||||||
|
client = pymongo.MongoClient(url, safe=True, max_pool_size=None)
|
||||||
|
else:
|
||||||
|
client = pymongo.MongoClient(url, safe=True)
|
||||||
self._pool[url] = weakref.ref(client)
|
self._pool[url] = weakref.ref(client)
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
import calendar
|
import calendar
|
||||||
import copy
|
import copy
|
||||||
import operator
|
import operator
|
||||||
|
import urlparse
|
||||||
import weakref
|
import weakref
|
||||||
|
|
||||||
import bson.code
|
import bson.code
|
||||||
@ -149,9 +150,15 @@ class ConnectionPool(object):
|
|||||||
if client:
|
if client:
|
||||||
return client
|
return client
|
||||||
LOG.info('connecting to MongoDB on %s', url)
|
LOG.info('connecting to MongoDB on %s', url)
|
||||||
client = pymongo.MongoClient(
|
url_parsed = urlparse.urlparse(url)
|
||||||
url,
|
if url_parsed.path.startswith('/ceilometer_for_tox_testing_'):
|
||||||
safe=True)
|
#note(sileht): this is a workaround for running tests without reach
|
||||||
|
#the maximum allowed connection of mongod in gate
|
||||||
|
#this only work with pymongo >= 2.6, this is not in the
|
||||||
|
#requirements file because is not needed for normal use of mongo
|
||||||
|
client = pymongo.MongoClient(url, safe=True, max_pool_size=None)
|
||||||
|
else:
|
||||||
|
client = pymongo.MongoClient(url, safe=True)
|
||||||
self._pool[url] = weakref.ref(client)
|
self._pool[url] = weakref.ref(client)
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ MONGO_DATA=`mktemp -d /tmp/CEILO-MONGODB-XXXXX`
|
|||||||
trap "clean_exit" EXIT
|
trap "clean_exit" EXIT
|
||||||
mkfifo ${MONGO_DATA}/out
|
mkfifo ${MONGO_DATA}/out
|
||||||
export PATH=${PATH:+$PATH:}/sbin:/usr/sbin
|
export PATH=${PATH:+$PATH:}/sbin:/usr/sbin
|
||||||
mongod --maxConns 256 --nojournal --noprealloc --smallfiles --quiet --noauth --port 29000 --dbpath "${MONGO_DATA}" --bind_ip localhost &>${MONGO_DATA}/out &
|
mongod --maxConns 32 --nojournal --noprealloc --smallfiles --quiet --noauth --port 29000 --dbpath "${MONGO_DATA}" --bind_ip localhost &>${MONGO_DATA}/out &
|
||||||
MONGO_PID=$!
|
MONGO_PID=$!
|
||||||
# Wait for Mongo to start listening to connections
|
# Wait for Mongo to start listening to connections
|
||||||
while read line
|
while read line
|
||||||
@ -36,5 +36,5 @@ done < ${MONGO_DATA}/out
|
|||||||
# Read the fifo for ever otherwise mongod would block
|
# Read the fifo for ever otherwise mongod would block
|
||||||
# + that gives us the log on screen
|
# + that gives us the log on screen
|
||||||
cat ${MONGO_DATA}/out > /dev/null &
|
cat ${MONGO_DATA}/out > /dev/null &
|
||||||
export CEILOMETER_TEST_MONGODB_URL="mongodb://localhost:29000/ceilometer"
|
export CEILOMETER_TEST_MONGODB_URL="mongodb://localhost:29000/ceilometer_for_tox_testing"
|
||||||
python setup.py testr --slowest --testr-args="$*" $COVERAGE_ARG
|
python setup.py testr --slowest --testr-args="$*" $COVERAGE_ARG
|
||||||
|
Loading…
Reference in New Issue
Block a user