Skip to content

Commit

Permalink
Merge pull request #10 from Sh1nku/test_multiple_clients
Browse files Browse the repository at this point in the history
Add test making sure that using multiple clients simultaneously works
  • Loading branch information
Sh1nku authored Jun 29, 2024
2 parents 5738d13 + 5f4011f commit b5dcd5d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
27 changes: 27 additions & 0 deletions framework/tests/functionality/client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}
12 changes: 8 additions & 4 deletions wrappers/python/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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),
)

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions wrappers/python/tests/test_clients.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import asyncio

import pytest
from helpers import Config, create_config

Expand Down Expand Up @@ -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)

0 comments on commit b5dcd5d

Please sign in to comment.