Skip to content

Commit 4981fae

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 4981fae

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-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_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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,32 @@ 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.get_cluster_state().get_nodes_info().first().unwrap().sharder().is_some() {
840+
assert!(tracing_info.duration.unwrap() > 0);
841+
}
842+
// Verify started_at timestamp is present
843+
assert!(tracing_info.started_at.unwrap().0 > 0);
844+
845+
// Check parameters
846+
assert!(tracing_info
847+
.parameters
848+
.clone()
849+
.unwrap()
850+
.contains_key("consistency_level"));
851+
assert!(tracing_info.parameters.unwrap().contains_key("query"));
852+
853+
// Check events
854+
for event in tracing_info.events {
855+
assert!(!event.activity.clone().unwrap().is_empty());
856+
assert!(event.source.is_some());
857+
assert!(event.source_elapsed.unwrap() >= 0);
858+
assert!(!event.activity.unwrap().is_empty());
859+
}
834860
}
835861

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

0 commit comments

Comments
 (0)