Skip to content

Commit

Permalink
test(query_result): cluster state tests
Browse files Browse the repository at this point in the history
Added tests around query response metadata:
1. initial test for cluster state (node addresses)
2. improved trace_info test with more detailed verification

based on:
com.datastax.oss.driver.core.metadata.MetadataIT
com.datastax.oss.driver.core.cql.QueryTraceIT
  • Loading branch information
soyacz committed Mar 4, 2025
1 parent f1de757 commit 37ba8ee
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
30 changes: 30 additions & 0 deletions scylla/tests/integration/cluster_state_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::env;

use hashbrown::HashSet;

use crate::utils::{create_new_session_builder, setup_tracing};

#[tokio::test]
#[ntest::timeout(60000)]
#[cfg(not(scylla_cloud_tests))]
async fn test_session_should_have_topology_metadata() {
setup_tracing();
let session = create_new_session_builder().build().await.unwrap();
let state = session.get_cluster_state();
let keys = ["SCYLLA_URI", "SCYLLA_URI2", "SCYLLA_URI3"];
let expected_addresses: HashSet<String> = keys
.iter()
.map(|key| env::var(key).unwrap_or_else(|_| panic!("{} not set", key)))
.collect();

let got_addresses: HashSet<String> = state
.get_nodes_info()
.iter()
.map(|node| node.address.to_string())
.collect();

assert_eq!(
got_addresses, expected_addresses,
"Cluster node addresses do not match environment variables"
);
}
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 authenticate;
mod batch;
mod cluster_state_tests;
mod consistency;
mod cql_collections;
mod cql_types;
Expand Down
63 changes: 63 additions & 0 deletions scylla/tests/integration/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,69 @@ async fn test_get_tracing_info(session: &Session, ks: String) {
let tracing_info: TracingInfo = session.get_tracing_info(&tracing_id).await.unwrap();
assert!(!tracing_info.events.is_empty());
assert!(!tracing_info.nodes().is_empty());

// Check if the request type matches
assert_eq!(tracing_info.request.as_ref().unwrap(), "Execute CQL3 query");

// Check if we're using Scylla or Cassandra
let is_scylla = session
.get_cluster_state()
.get_nodes_info()
.first()
.unwrap()
.sharder()
.is_some();

if is_scylla {
// For Scylla, duration should be available immediately
assert!(tracing_info.duration.unwrap() > 0);
} else {
// For Cassandra, we might need to wait for the duration
let mut attempts = 0;
let max_attempts = 10;
let mut duration_opt;

while attempts < max_attempts {
duration_opt = session
.get_tracing_info(&tracing_id)
.await
.unwrap()
.duration;
if let Some(duration) = duration_opt {
assert!(duration > 0);
break;
}
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
attempts += 1;
}

if attempts == max_attempts {
panic!("Duration was not available after {} attempts", max_attempts);
}
}

// Verify started_at timestamp is present
assert!(tracing_info.started_at.unwrap().0 > 0);

// Check parameters
assert!(tracing_info
.parameters
.as_ref()
.unwrap()
.contains_key("consistency_level"));
assert!(tracing_info
.parameters
.as_ref()
.unwrap()
.contains_key("query"));

// Check events
for event in &tracing_info.events {
assert!(!event.activity.as_ref().unwrap().is_empty());
assert!(event.source.is_some());
assert!(event.source_elapsed.unwrap() >= 0);
assert!(!event.activity.as_ref().unwrap().is_empty());
}
}

async fn test_tracing_query_iter(session: &Session, ks: String) {
Expand Down

0 comments on commit 37ba8ee

Please sign in to comment.