Finish up #305, tests for AsyncTransport (#452)

* 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 <adil.rashitov.98@gmail.com>

* adding test cases for checking multihost connection pool init with specified connection_class object

Signed-off-by: ARashitov <adil.rashitov.98@gmail.com>

* remove introduced updates

Signed-off-by: ARashitov <adil.rashitov.98@gmail.com>

* fix test cases by adding _async_init() call to init the actual hosts

Signed-off-by: ARashitov <adil.rashitov.98@gmail.com>

* remove unneeded imports

Signed-off-by: ARashitov <adil.rashitov.98@gmail.com>

* fix test cases of multi hosts connection pool init & adding documentation

Signed-off-by: ARashitov <adil.rashitov.98@gmail.com>

* Addressed comments in #305.

Signed-off-by: dblock <dblock@amazon.com>

* Renamed file for consistency.

Signed-off-by: dblock <dblock@amazon.com>

---------

Signed-off-by: ARashitov <adil.rashitov.98@gmail.com>
Signed-off-by: dblock <dblock@amazon.com>
Co-authored-by: ARashitov <adil.rashitov.98@gmail.com>
This commit is contained in:
Daniel (dB.) Doubrovkine
2023-07-26 12:45:52 -05:00
committed by GitHub
parent e022932ed1
commit 87b402c16e
2 changed files with 41 additions and 1 deletions
+41 -1
View File
@@ -34,7 +34,7 @@ import json
import pytest
from mock import patch
from opensearchpy import AsyncTransport
from opensearchpy import AIOHttpConnection, AsyncTransport
from opensearchpy.connection import Connection
from opensearchpy.connection_pool import DummyConnectionPool
from opensearchpy.exceptions import ConnectionError, TransportError
@@ -543,3 +543,43 @@ class TestTransport:
# A lot quicker than 10 seconds defined in 'delay'
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,
)