* fix multihost connection of AsyncTransport for AIOHttpConnection as connection_class & ConnectionPool as connection_pool_class parameters with compatability legacy test cases Signed-off-by: ARashitov <[email protected]> * adding test cases for checking multihost connection pool init with specified connection_class object Signed-off-by: ARashitov <[email protected]> * remove introduced updates Signed-off-by: ARashitov <[email protected]> * fix test cases by adding _async_init() call to init the actual hosts Signed-off-by: ARashitov <[email protected]> * remove unneeded imports Signed-off-by: ARashitov <[email protected]> * fix test cases of multi hosts connection pool init & adding documentation Signed-off-by: ARashitov <[email protected]> * Addressed comments in #305. Signed-off-by: dblock <[email protected]> * Renamed file for consistency. Signed-off-by: dblock <[email protected]> --------- Signed-off-by: ARashitov <[email protected]> Signed-off-by: dblock <[email protected]> Co-authored-by: ARashitov <[email protected]>
This commit is contained in:
co-authored by
ARashitov
parent
e022932ed1
commit
87b402c16e
@@ -34,7 +34,7 @@ import json
|
|||||||
import pytest
|
import pytest
|
||||||
from mock import patch
|
from mock import patch
|
||||||
|
|
||||||
from opensearchpy import AsyncTransport
|
from opensearchpy import AIOHttpConnection, AsyncTransport
|
||||||
from opensearchpy.connection import Connection
|
from opensearchpy.connection import Connection
|
||||||
from opensearchpy.connection_pool import DummyConnectionPool
|
from opensearchpy.connection_pool import DummyConnectionPool
|
||||||
from opensearchpy.exceptions import ConnectionError, TransportError
|
from opensearchpy.exceptions import ConnectionError, TransportError
|
||||||
@@ -543,3 +543,43 @@ class TestTransport:
|
|||||||
|
|
||||||
# A lot quicker than 10 seconds defined in 'delay'
|
# A lot quicker than 10 seconds defined in 'delay'
|
||||||
assert duration < 1
|
assert duration < 1
|
||||||
|
|
||||||
|
async def test_init_connection_pool_with_many_hosts(self):
|
||||||
|
"""
|
||||||
|
Check init of connection pool with multiple connections.
|
||||||
|
|
||||||
|
NOTE: since AsyncTransport performs internal hosts sniffing
|
||||||
|
after building a connection the actual init of connection_class
|
||||||
|
instances is reallocated from AsyncTransport.__init__()
|
||||||
|
to AsyncTransport._async_init
|
||||||
|
"""
|
||||||
|
amt_hosts = 4
|
||||||
|
hosts = [{"host": "localhost", "port": 9092}] * amt_hosts
|
||||||
|
t = AsyncTransport(
|
||||||
|
hosts=hosts,
|
||||||
|
)
|
||||||
|
await t._async_init()
|
||||||
|
assert len(t.connection_pool.connections) == amt_hosts
|
||||||
|
await t._async_call()
|
||||||
|
|
||||||
|
async def test_init_pool_with_connection_class_to_many_hosts(self):
|
||||||
|
"""
|
||||||
|
Check init of connection pool with user specified connection_class.
|
||||||
|
|
||||||
|
NOTE: since AsyncTransport performs internal hosts sniffing
|
||||||
|
after building a connection the actual init of connection_class
|
||||||
|
instances is reallocated from AsyncTransport.__init__()
|
||||||
|
to AsyncTransport._async_init
|
||||||
|
"""
|
||||||
|
amt_hosts = 4
|
||||||
|
hosts = [{"host": "localhost", "port": 9092}] * amt_hosts
|
||||||
|
t = AsyncTransport(
|
||||||
|
hosts=hosts,
|
||||||
|
connection_class=AIOHttpConnection,
|
||||||
|
)
|
||||||
|
await t._async_init()
|
||||||
|
assert len(t.connection_pool.connections) == amt_hosts
|
||||||
|
assert isinstance(
|
||||||
|
t.connection_pool.connections[0],
|
||||||
|
AIOHttpConnection,
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user