Skip to content

Commit 37ba8ee

Browse files
committed
test(query_result): cluster state tests
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
1 parent f1de757 commit 37ba8ee

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::env;
2+
3+
use hashbrown::HashSet;
4+
5+
use crate::utils::{create_new_session_builder, setup_tracing};
6+
7+
#[tokio::test]
8+
#[ntest::timeout(60000)]
9+
#[cfg(not(scylla_cloud_tests))]
10+
async fn test_session_should_have_topology_metadata() {
11+
setup_tracing();
12+
let session = create_new_session_builder().build().await.unwrap();
13+
let state = session.get_cluster_state();
14+
let keys = ["SCYLLA_URI", "SCYLLA_URI2", "SCYLLA_URI3"];
15+
let expected_addresses: HashSet<String> = keys
16+
.iter()
17+
.map(|key| env::var(key).unwrap_or_else(|_| panic!("{} not set", key)))
18+
.collect();
19+
20+
let got_addresses: HashSet<String> = state
21+
.get_nodes_info()
22+
.iter()
23+
.map(|node| node.address.to_string())
24+
.collect();
25+
26+
assert_eq!(
27+
got_addresses, expected_addresses,
28+
"Cluster node addresses do not match environment variables"
29+
);
30+
}

scylla/tests/integration/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mod authenticate;
22
mod batch;
3+
mod cluster_state_tests;
34
mod consistency;
45
mod cql_collections;
56
mod cql_types;

scylla/tests/integration/session.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,69 @@ async fn test_get_tracing_info(session: &Session, ks: String) {
831831
let tracing_info: TracingInfo = session.get_tracing_info(&tracing_id).await.unwrap();
832832
assert!(!tracing_info.events.is_empty());
833833
assert!(!tracing_info.nodes().is_empty());
834+
835+
// Check if the request type matches
836+
assert_eq!(tracing_info.request.as_ref().unwrap(), "Execute CQL3 query");
837+
838+
// Check if we're using Scylla or Cassandra
839+
let is_scylla = session
840+
.get_cluster_state()
841+
.get_nodes_info()
842+
.first()
843+
.unwrap()
844+
.sharder()
845+
.is_some();
846+
847+
if is_scylla {
848+
// For Scylla, duration should be available immediately
849+
assert!(tracing_info.duration.unwrap() > 0);
850+
} else {
851+
// For Cassandra, we might need to wait for the duration
852+
let mut attempts = 0;
853+
let max_attempts = 10;
854+
let mut duration_opt;
855+
856+
while attempts < max_attempts {
857+
duration_opt = session
858+
.get_tracing_info(&tracing_id)
859+
.await
860+
.unwrap()
861+
.duration;
862+
if let Some(duration) = duration_opt {
863+
assert!(duration > 0);
864+
break;
865+
}
866+
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
867+
attempts += 1;
868+
}
869+
870+
if attempts == max_attempts {
871+
panic!("Duration was not available after {} attempts", max_attempts);
872+
}
873+
}
874+
875+
// Verify started_at timestamp is present
876+
assert!(tracing_info.started_at.unwrap().0 > 0);
877+
878+
// Check parameters
879+
assert!(tracing_info
880+
.parameters
881+
.as_ref()
882+
.unwrap()
883+
.contains_key("consistency_level"));
884+
assert!(tracing_info
885+
.parameters
886+
.as_ref()
887+
.unwrap()
888+
.contains_key("query"));
889+
890+
// Check events
891+
for event in &tracing_info.events {
892+
assert!(!event.activity.as_ref().unwrap().is_empty());
893+
assert!(event.source.is_some());
894+
assert!(event.source_elapsed.unwrap() >= 0);
895+
assert!(!event.activity.as_ref().unwrap().is_empty());
896+
}
834897
}
835898

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

0 commit comments

Comments
 (0)