Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/channel_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ impl ChannelPool {
0
}
}

/// Explicitly establishes a connection to at least one channel in the pool.
/// This triggers the underlying gRPC handshake.
pub async fn connect(&self) -> Result<(), Status> {
let _ = self.get_channel().await?;
Ok(())
}
}

// The future returned by get_channel needs to be Send so that the client can be
Expand Down
8 changes: 8 additions & 0 deletions src/qdrant_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,12 @@ impl Qdrant {
})
.await
}

/// Performs a connectivity check to the Qdrant server.
///
/// This method forces the client to establish a connection immediately.
/// Returns an error if the TCP connection or gRPC handshake fails.
pub async fn connect(&self) -> QdrantResult<()> {
self.channel.connect().await.map_err(Into::into)
}
}
1 change: 1 addition & 0 deletions tests/snippet_tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod test_batch_update;
mod test_clear_payload;
mod test_collection_exists;
mod test_connect;
mod test_count_points;
mod test_create_collection;
mod test_create_collection_with_bq;
Expand Down
20 changes: 20 additions & 0 deletions tests/snippet_tests/test_connect.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

#[tokio::test]
async fn test_connect() {
async fn connect() -> Result<(), Box<dyn std::error::Error>> {
// WARNING: This is a generated test snippet.
// Please, modify the snippet in the `../snippets/connect.rs` file
use qdrant_client::Qdrant;
use std::time::Duration;

let client = Qdrant::from_url("http://localhost:1234")
.connect_timeout(Duration::from_millis(500))
.build()?;

let connection_result = client.connect().await;

assert!(connection_result.is_err());
Ok(())
}
let _ = connect().await;
}
28 changes: 28 additions & 0 deletions tests/snippet_tests/test_verify_connection_failure.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

#[tokio::test]
async fn test_verify_connection_failure() {
async fn verify_connection_failure() -> Result<(), Box<dyn std::error::Error>> {
// WARNING: This is a generated test snippet.
// Please, modify the snippet in the `../snippets/verify_connection_failure.rs` file
#[tokio::test]
async fn test_verify_connection_failure() {
use crate::qdrant_client::Qdrant;

// We use an address that doesn't respond
let client = Qdrant::from_url("http://127.0.0.1:1234")
.connect_timeout(std::time::Duration::from_millis(500))
.build()
.unwrap();

// build() always succeeds (lazy behavior),
// but connect() should detect the failure.
let result = client.connect().await;
assert!(
result.is_err(),
"The connection should have failed on an invalid port"
);
}
Ok(())
}
let _ = verify_connection_failure().await;
}
10 changes: 10 additions & 0 deletions tests/snippets/connect.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use qdrant_client::Qdrant;
use std::time::Duration;

let client = Qdrant::from_url("http://localhost:1234")
.connect_timeout(Duration::from_millis(500))
.build()?;

let connection_result = client.connect().await;

assert!(connection_result.is_err());