Skip to content

Commit 8303492

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 8303492

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,39 @@ 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.unwrap(), "Execute CQL3 query");
837+
838+
// Verify duration is positive when Scylla is used
839+
if session
840+
.get_cluster_state()
841+
.get_nodes_info()
842+
.first()
843+
.unwrap()
844+
.sharder()
845+
.is_some()
846+
{
847+
assert!(tracing_info.duration.unwrap() > 0);
848+
}
849+
// Verify started_at timestamp is present
850+
assert!(tracing_info.started_at.unwrap().0 > 0);
851+
852+
// Check parameters
853+
assert!(tracing_info
854+
.parameters
855+
.as_ref()
856+
.unwrap()
857+
.contains_key("consistency_level"));
858+
assert!(tracing_info.parameters.as_ref().unwrap().contains_key("query"));
859+
860+
// Check events
861+
for event in tracing_info.events {
862+
assert!(!event.activity.as_ref().unwrap().is_empty());
863+
assert!(event.source.is_some());
864+
assert!(event.source_elapsed.unwrap() >= 0);
865+
assert!(!event.activity.as_ref().unwrap().is_empty());
866+
}
834867
}
835868

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

0 commit comments

Comments
 (0)