Skip to content

Commit

Permalink
integration: add tests for hostname resolution
Browse files Browse the repository at this point in the history
Two scenarios are tested:
1) when some hostnames are invalid, but there are some addresses
   resolved successfully, initialisation continues without an error,
2) when all hostnames are invalid, and there are no adresses given,
   then NewSessionError::FailedToResolveAnyHostname is returned.
  • Loading branch information
wprzytula committed Jul 1, 2023
1 parent 5006625 commit 172f7a0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions scylla/tests/integration/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod execution_profiles;
mod hygiene;
mod lwt_optimisation;
mod new_session;
mod retries;
pub(crate) mod utils;
34 changes: 34 additions & 0 deletions scylla/tests/integration/new_session.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use assert_matches::assert_matches;
use scylla::SessionBuilder;
use scylla_cql::errors::NewSessionError;

#[cfg(not(scylla_cloud_tests))]
#[tokio::test]
async fn proceed_if_only_some_hostnames_are_invalid() {
// on purpose left without port
let uri1 = "scylladbisthefastest.db".to_owned();
// correctly provided port, but unknown domain
let uri2 = "cassandrasuckssomu.ch:9042".to_owned();
let uri3 = std::env::var("SCYLLA_URI3").unwrap_or_else(|_| "127.0.0.3:9042".to_string());

let session = SessionBuilder::new()
.known_nodes([uri1, uri2, uri3])
.build()
.await
.unwrap();
session
.query("SELECT host_id FROM system.local", &[])
.await
.unwrap();
}

#[cfg(not(scylla_cloud_tests))]
#[tokio::test]
async fn all_hostnames_invalid() {
let uri = "cassandrasuckssomu.ch:9042".to_owned();

assert_matches!(
SessionBuilder::new().known_node(uri).build().await,
Err(NewSessionError::FailedToResolveAnyHostname(_))
);
}

0 comments on commit 172f7a0

Please sign in to comment.