From 5f4011f8f9d5bfc342fe059469d7c01a4880e818 Mon Sep 17 00:00:00 2001 From: Sh1nku <42642351+Sh1nku@users.noreply.github.com> Date: Sat, 29 Jun 2024 14:59:08 +0200 Subject: [PATCH] Add test making sure that using multiple clients simultaneously works --- framework/tests/functionality/client_tests.rs | 27 +++++++++++++++++++ wrappers/python/tests/helpers.py | 12 ++++++--- wrappers/python/tests/test_clients.py | 26 ++++++++++++++++++ 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/framework/tests/functionality/client_tests.rs b/framework/tests/functionality/client_tests.rs index b4f86b0..0866fe6 100644 --- a/framework/tests/functionality/client_tests.rs +++ b/framework/tests/functionality/client_tests.rs @@ -4,6 +4,7 @@ use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; use solrstice::queries::index::{DeleteQuery, UpdateQuery}; use solrstice::queries::select::SelectQuery; use std::path::Path; +use tokio::join; #[derive(Serialize, Deserialize, Debug)] struct TestData { @@ -58,3 +59,29 @@ pub async fn client_example_test() { // Delete config client.delete_config(name).await.unwrap(); } + +#[tokio::test] +pub async fn multiple_clients_test() { + let name = "multiple_clients_test".to_string(); + let config_1 = BaseTestsBuildup::new().await; + let config_2 = BaseTestsBuildup::new().await; + let client_1 = AsyncSolrCloudClient::new(config_1.context); + let client_2 = AsyncSolrCloudClient::new(config_2.context); + + let _ = client_1.delete_config(&name).await; + + client_1 + .upload_config(&name, Path::new(&config_1.config_path)) + .await + .unwrap(); + + let configs_1_future = client_1.get_configs(); + let configs_2_future = client_2.get_configs(); + + let configs_tup = join!(configs_1_future, configs_2_future); + + assert!(configs_tup.0.unwrap().contains(&name)); + assert!(configs_tup.1.unwrap().contains(&name)); + + client_1.delete_config(&name).await.unwrap(); +} diff --git a/wrappers/python/tests/helpers.py b/wrappers/python/tests/helpers.py index 89d4cff..da81198 100644 --- a/wrappers/python/tests/helpers.py +++ b/wrappers/python/tests/helpers.py @@ -28,7 +28,11 @@ class Config: def create_config() -> Config: - path = "../../test_setup/.env" + path_prefix = "../../" + if not os.path.exists(os.path.join(path_prefix, "test_setup/.env")): + path_prefix = "../../../" + + path = os.path.join(path_prefix, "test_setup/.env") load_dotenv(path) solr_auth = None solr_username = os.getenv("SOLR_USERNAME") @@ -46,7 +50,7 @@ def create_config() -> Config: solr_username, solr_password, context, - "../../test_setup/test_collection", + os.path.join(path_prefix, "test_setup/test_collection"), AsyncSolrCloudClient(context), ) @@ -56,7 +60,7 @@ def wait_for_solr(host: str, max_time: int): while time.time() < end: try: with urlopen( - f'{host}{"/solr/admin/collections"}?action=CLUSTERSTATUS' + f'{host}{"/solr/admin/collections"}?action=CLUSTERSTATUS' ) as response: if response.status == 200: return @@ -98,7 +102,7 @@ async def index_test_data(context: SolrServerContext, name: str) -> None: async def setup_collection( - context: SolrServerContext, name: str, config_path: str + context: SolrServerContext, name: str, config_path: str ) -> None: try: await delete_collection(context, name) diff --git a/wrappers/python/tests/test_clients.py b/wrappers/python/tests/test_clients.py index 48225b8..7f80677 100644 --- a/wrappers/python/tests/test_clients.py +++ b/wrappers/python/tests/test_clients.py @@ -1,3 +1,5 @@ +import asyncio + import pytest from helpers import Config, create_config @@ -67,3 +69,27 @@ def test_blocking_client_works(config: Config): client.delete_collection(name) client.delete_config(name) + + +@pytest.mark.asyncio +async def test_multiple_clients_works(): + name = "MultipleClientWorks" + + config_1 = create_config() + config_2 = create_config() + + client = AsyncSolrCloudClient(config_1.context) + client_2 = AsyncSolrCloudClient(config_2.context) + + try: + await client.delete_config(name) + except: + pass + + await client.upload_config(name, config_1.config_path) + + results = await asyncio.gather(*[client.get_configs(), client_2.get_configs()]) + assert name in results[0] + assert name in results[1] + + await client.delete_config(name)