Take last host if multiple defined
This commit is contained in:
@@ -54,7 +54,7 @@ class Pool:
|
||||
except (AttributeError, ValueError):
|
||||
raise Exception("Missing database name in URI")
|
||||
|
||||
self._host = url.hostname
|
||||
host = url.hostname
|
||||
|
||||
try:
|
||||
port = url.port
|
||||
@@ -63,10 +63,15 @@ class Pool:
|
||||
# strip any additional hosts in the connection string for now
|
||||
try:
|
||||
if "," in port:
|
||||
port = port[:port.find(',')]
|
||||
hosts = port.split(",")
|
||||
netloc = hosts[len(hosts)-1]
|
||||
netloc = netloc.split(':')
|
||||
host = netloc[0]
|
||||
port = netloc[1]
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
self._host = host
|
||||
self._port = port or 27017
|
||||
username = url.username
|
||||
password = url.password
|
||||
|
||||
@@ -45,7 +45,7 @@ class TestMongoConnectionMethods(MongoTest):
|
||||
@async
|
||||
def test_pool_multiple_hosts(self):
|
||||
# MongoConnectionPool returns deferred, which gets MongoAPI
|
||||
pool = asyncio_mongo.Pool.create(url="mongodb://{host}:{port},otherhost:333".format(
|
||||
pool = asyncio_mongo.Pool.create(url="mongodb://blahhost:333,{host}:{port}".format(
|
||||
host=mongo_host, port=mongo_port), poolsize=2)
|
||||
self.assertTrue(inspect.isgenerator(pool))
|
||||
rapi = yield from pool
|
||||
|
||||
Reference in New Issue
Block a user