Skip to content

Commit 97d9698

Browse files
committed
Add stale keyspaces detector
Previous commits changed all the integration tests to drop keyspaces after finishing. We want to enforce in CI that no keyspaces are left after tests finish. I don't see better way of doing that than create a separate small program that looks through existing keyspaces, filters out non-test ones, and prints schemas of the stale ones. This commit implements such program. Now we will be able to add CI steps that call it after finishing tests. This of course does not help with ccm tests. In the future we can solve this in custom test framework, or by looking through cluster metadata after each ccm test (before destroying the cluster).
1 parent 2a940bb commit 97d9698

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

Cargo.lock.msrv

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ members = [
55
"scylla-macros",
66
"scylla-cql",
77
"scylla-proxy",
8+
"utils",
89
]
910
resolver = "2"

utils/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
edition = "2021"
3+
name = "utils"
4+
publish = false
5+
version = "0.0.0"
6+
7+
[dependencies]
8+
scylla = { path = "../scylla" }
9+
tokio = { version = "1.34", features = ["rt", "rt-multi-thread", "macros"] }
10+
futures = "0.3.6"
11+
12+
[[bin]]
13+
name = "find_stale_test_keyspaces"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use futures::{stream, StreamExt};
2+
use scylla::client::session::Session;
3+
use scylla::client::session_builder::SessionBuilder;
4+
5+
#[tokio::main]
6+
async fn main() {
7+
let uri = std::env::var("SCYLLA_URI").unwrap_or_else(|_| "127.0.0.1:9042".to_string());
8+
9+
println!("Connecting to {uri} ...");
10+
11+
let session: Session = SessionBuilder::new()
12+
.known_node(uri)
13+
.build()
14+
.await
15+
.expect("Can't connect to cluster");
16+
session
17+
.refresh_metadata()
18+
.await
19+
.expect("Can't refresh metadata");
20+
let state = session.get_cluster_state();
21+
let keyspaces_stream = stream::iter(state.keyspaces_iter());
22+
let nr_stale = keyspaces_stream
23+
.filter_map(|(name, _ks)| {
24+
let session = &session;
25+
async move {
26+
if !name.starts_with("test_rust_") {
27+
return None;
28+
}
29+
let describe_result = session
30+
.query_unpaged(format!("DESCRIBE {name}"), &[])
31+
.await
32+
.expect("Can't perform DESCRIBE request")
33+
.into_rows_result()
34+
.expect("Wrong response type for DESCRIBE request");
35+
println!("Found stale keyspace: {name}");
36+
println!("Schema:");
37+
for (_, _, _, describe_text) in describe_result
38+
.rows::<(&str, &str, &str, &str)>()
39+
.expect("Wrong response metadata for DESCRIBE request")
40+
.map(|r| r.expect("Failed to deserialize a row of RESPONSE request"))
41+
{
42+
println!("{describe_text}");
43+
}
44+
45+
Some(())
46+
}
47+
})
48+
.count()
49+
.await;
50+
51+
if nr_stale > 0 {
52+
panic!("Found stale keyspaces");
53+
}
54+
}

0 commit comments

Comments
 (0)