From 87b402c16eb316bcdb6d12b11ec6cae3dad1eeae Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Wed, 26 Jul 2023 12:45:52 -0500 Subject: [PATCH] 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 * adding test cases for checking multihost connection pool init with specified connection_class object Signed-off-by: ARashitov * remove introduced updates Signed-off-by: ARashitov * fix test cases by adding _async_init() call to init the actual hosts Signed-off-by: ARashitov * remove unneeded imports Signed-off-by: ARashitov * fix test cases of multi hosts connection pool init & adding documentation Signed-off-by: ARashitov * Addressed comments in #305. Signed-off-by: dblock * Renamed file for consistency. Signed-off-by: dblock --------- Signed-off-by: ARashitov Signed-off-by: dblock Co-authored-by: ARashitov --- .../{test_asyncsigner.py => test_signer.py} | 0 .../test_async/test_transport.py | 42 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) rename test_opensearchpy/test_async/{test_asyncsigner.py => test_signer.py} (100%) diff --git a/test_opensearchpy/test_async/test_asyncsigner.py b/test_opensearchpy/test_async/test_signer.py similarity index 100% rename from test_opensearchpy/test_async/test_asyncsigner.py rename to test_opensearchpy/test_async/test_signer.py diff --git a/test_opensearchpy/test_async/test_transport.py b/test_opensearchpy/test_async/test_transport.py index a9bc3565..fc018e43 100644 --- a/test_opensearchpy/test_async/test_transport.py +++ b/test_opensearchpy/test_async/test_transport.py @@ -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, + )