|
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | +# |
| 3 | +# The OpenSearch Contributors require contributions made to |
| 4 | +# this file be licensed under the Apache-2.0 license or a |
| 5 | +# compatible open source license. |
| 6 | +# |
| 7 | +# Modifications Copyright OpenSearch Contributors. See |
| 8 | +# GitHub history for details. |
| 9 | +import os |
| 10 | +from typing import Type |
| 11 | + |
| 12 | +import pytest |
| 13 | +from pytest import MarkDecorator |
| 14 | + |
| 15 | +from opensearchpy import ( |
| 16 | + AIOHttpConnection, |
| 17 | + AsyncConnection, |
| 18 | + AsyncHttpConnection, |
| 19 | + AsyncOpenSearch, |
| 20 | +) |
| 21 | +from opensearchpy._async.helpers.test import get_test_client |
| 22 | + |
| 23 | +pytestmark: MarkDecorator = pytest.mark.asyncio |
| 24 | + |
| 25 | + |
| 26 | +class TestAIOHttp: |
| 27 | + |
| 28 | + def test_default(self) -> None: |
| 29 | + client = AsyncOpenSearch() |
| 30 | + assert client.transport.connection_class == AIOHttpConnection |
| 31 | + assert client.transport.pool_maxsize is None |
| 32 | + |
| 33 | + def test_connection_class(self) -> None: |
| 34 | + client = AsyncOpenSearch(connection_class=AsyncHttpConnection) |
| 35 | + assert client.transport.connection_class == AsyncHttpConnection |
| 36 | + assert client.transport.pool_maxsize is None |
| 37 | + |
| 38 | + def test_pool_maxsize(self) -> None: |
| 39 | + client = AsyncOpenSearch(connection_class=AsyncHttpConnection, pool_maxsize=42) |
| 40 | + assert client.transport.connection_class == AsyncHttpConnection |
| 41 | + assert client.transport.pool_maxsize == 42 |
| 42 | + |
| 43 | + @pytest.mark.parametrize( # type: ignore[misc] |
| 44 | + "connection_class", [AIOHttpConnection, AsyncHttpConnection] |
| 45 | + ) |
| 46 | + async def test_default_limit(self, connection_class: Type[AsyncConnection]) -> None: |
| 47 | + client = await get_test_client( |
| 48 | + connection_class=connection_class, |
| 49 | + verify_certs=False, |
| 50 | + http_auth=("admin", os.getenv("OPENSEARCH_PASSWORD", "admin")), |
| 51 | + ) |
| 52 | + assert isinstance( |
| 53 | + client.transport.connection_pool.connections[0], connection_class |
| 54 | + ) |
| 55 | + assert ( |
| 56 | + client.transport.connection_pool.connections[0].session.connector.limit # type: ignore[attr-defined] |
| 57 | + == 10 |
| 58 | + ) |
| 59 | + |
| 60 | + @pytest.mark.parametrize( # type: ignore[misc] |
| 61 | + "connection_class", [AIOHttpConnection, AsyncHttpConnection] |
| 62 | + ) |
| 63 | + async def test_custom_limit(self, connection_class: Type[AsyncConnection]) -> None: |
| 64 | + client = await get_test_client( |
| 65 | + connection_class=connection_class, |
| 66 | + verify_certs=False, |
| 67 | + pool_maxsize=42, |
| 68 | + http_auth=("admin", os.getenv("OPENSEARCH_PASSWORD", "admin")), |
| 69 | + ) |
| 70 | + assert isinstance( |
| 71 | + client.transport.connection_pool.connections[0], connection_class |
| 72 | + ) |
| 73 | + assert ( |
| 74 | + client.transport.connection_pool.connections[0].session.connector.limit # type: ignore[attr-defined] |
| 75 | + == 42 |
| 76 | + ) |
0 commit comments