Skip to content

Commit 4c11a4c

Browse files
committed
Copy test utils into integration tests
As a small side change it changes "supports_feature" to use zero-copy deserialization to &str.
1 parent dbcb168 commit 4c11a4c

File tree

2 files changed

+113
-3
lines changed

2 files changed

+113
-3
lines changed

scylla/src/utils/test_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ pub(crate) async fn supports_feature(session: &Session, feature: &str) -> bool {
4444
return false;
4545
}
4646

47-
let (features,): (Option<String>,) = session
47+
let result = session
4848
.query_unpaged("SELECT supported_features FROM system.local", ())
4949
.await
5050
.unwrap()
5151
.into_rows_result()
52-
.unwrap()
53-
.single_row()
5452
.unwrap();
5553

54+
let (features,): (Option<&str>,) = result.single_row().unwrap();
55+
5656
features
5757
.unwrap_or_default()
5858
.split(',')

scylla/tests/integration/utils.rs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
use futures::Future;
2+
use scylla::frame::response::result::Row;
3+
use scylla::transport::session_builder::{GenericSessionBuilder, SessionBuilderKind};
4+
use scylla::Session;
25
use std::collections::HashMap;
36
use std::env;
47
use std::net::SocketAddr;
8+
use std::num::NonZeroU32;
59
use std::str::FromStr;
10+
use std::sync::atomic::{AtomicUsize, Ordering};
11+
use std::time::{Duration, SystemTime, UNIX_EPOCH};
612

713
use scylla_proxy::{Node, Proxy, ProxyError, RunningProxy, ShardAwareness};
814

@@ -14,6 +20,23 @@ pub(crate) fn setup_tracing() {
1420
.try_init();
1521
}
1622

23+
static UNIQUE_COUNTER: AtomicUsize = AtomicUsize::new(0);
24+
25+
#[allow(unused)]
26+
pub(crate) fn unique_keyspace_name() -> String {
27+
let cnt = UNIQUE_COUNTER.fetch_add(1, Ordering::SeqCst);
28+
let name = format!(
29+
"test_rust_{}_{}",
30+
SystemTime::now()
31+
.duration_since(UNIX_EPOCH)
32+
.unwrap()
33+
.as_secs(),
34+
cnt
35+
);
36+
println!("Unique name: {}", name);
37+
name
38+
}
39+
1740
pub(crate) async fn test_with_3_node_cluster<F, Fut>(
1841
shard_awareness: ShardAwareness,
1942
test: F,
@@ -63,3 +86,90 @@ where
6386

6487
running_proxy.finish().await
6588
}
89+
90+
#[allow(unused)]
91+
pub(crate) async fn supports_feature(session: &Session, feature: &str) -> bool {
92+
// Cassandra doesn't have a concept of features, so first detect
93+
// if there is the `supported_features` column in system.local
94+
95+
let meta = session.get_cluster_data();
96+
let system_local = meta
97+
.get_keyspace_info()
98+
.get("system")
99+
.unwrap()
100+
.tables
101+
.get("local")
102+
.unwrap();
103+
104+
if !system_local.columns.contains_key("supported_features") {
105+
return false;
106+
}
107+
108+
let result = session
109+
.query_unpaged("SELECT supported_features FROM system.local", ())
110+
.await
111+
.unwrap()
112+
.into_rows_result()
113+
.unwrap();
114+
115+
let (features,): (Option<&str>,) = result.single_row().unwrap();
116+
117+
features
118+
.unwrap_or_default()
119+
.split(',')
120+
.any(|f| f == feature)
121+
}
122+
123+
#[allow(unused)]
124+
pub(crate) async fn scylla_supports_tablets(session: &Session) -> bool {
125+
let result = session
126+
.query_unpaged(
127+
"select column_name from system_schema.columns where
128+
keyspace_name = 'system_schema'
129+
and table_name = 'scylla_keyspaces'
130+
and column_name = 'initial_tablets'",
131+
&[],
132+
)
133+
.await
134+
.unwrap()
135+
.into_rows_result();
136+
137+
result.is_ok_and(|rows_result| rows_result.single_row::<Row>().is_ok())
138+
}
139+
140+
// Creates a generic session builder based on conditional compilation configuration
141+
// For SessionBuilder of DefaultMode type, adds localhost to known hosts, as all of the tests
142+
// connect to localhost.
143+
#[allow(unused)]
144+
pub(crate) fn create_new_session_builder() -> GenericSessionBuilder<impl SessionBuilderKind> {
145+
let session_builder = {
146+
#[cfg(not(scylla_cloud_tests))]
147+
{
148+
use scylla::SessionBuilder;
149+
150+
let uri = std::env::var("SCYLLA_URI").unwrap_or_else(|_| "127.0.0.1:9042".to_string());
151+
152+
SessionBuilder::new().known_node(uri)
153+
}
154+
155+
#[cfg(scylla_cloud_tests)]
156+
{
157+
use scylla::transport::session_builder::CloudMode;
158+
use scylla::CloudSessionBuilder;
159+
use std::path::Path;
160+
161+
std::env::var("CLOUD_CONFIG_PATH")
162+
.map(|config_path| CloudSessionBuilder::new(Path::new(&config_path)))
163+
.expect("Failed to initialize CloudSessionBuilder")
164+
.expect("CLOUD_CONFIG_PATH environment variable is missing")
165+
}
166+
};
167+
168+
// The reason why we enable so long waiting for TracingInfo is... Cassandra. (Yes, again.)
169+
// In Cassandra Java Driver, the wait time for tracing info is 10 seconds, so here we do the same.
170+
// However, as Scylla usually gets TracingInfo ready really fast (our default interval is hence 3ms),
171+
// we stick to a not-so-much-terribly-long interval here.
172+
session_builder
173+
.tracing_info_fetch_attempts(NonZeroU32::new(200).unwrap())
174+
.tracing_info_fetch_interval(Duration::from_millis(50))
175+
}

0 commit comments

Comments
 (0)