Skip to content

Commit 68dd529

Browse files
authored
Merge pull request #1414 from Lorak-mmk/drop_keyspaces
Drop keyspaces after tests
2 parents 0142025 + f336093 commit 68dd529

36 files changed

+441
-69
lines changed

.github/workflows/cassandra.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ jobs:
2828
uses: actions-rust-lang/setup-rust-toolchain@v1
2929
- name: Run tests on cassandra
3030
run: |
31-
CDC='disabled' RUSTFLAGS="--cfg cassandra_tests" RUST_LOG=trace SCYLLA_URI=172.42.0.2:9042 SCYLLA_URI2=172.42.0.3:9042 SCYLLA_URI3=172.42.0.4:9042 cargo test --features "full-serialization" -- --skip test_views_in_schema_info --skip test_large_batch_statements
31+
RUSTFLAGS="--cfg cassandra_tests" RUST_LOG=trace SCYLLA_URI=172.42.0.2:9042 SCYLLA_URI2=172.42.0.3:9042 SCYLLA_URI3=172.42.0.4:9042 cargo test --features "full-serialization" -- --skip test_views_in_schema_info --skip test_large_batch_statements
32+
- name: Check for stale test keyspaces
33+
run: SCYLLA_URI=172.42.0.2:9042 cargo run --bin find_stale_test_keyspaces
3234
- name: Stop the cluster
3335
if: ${{ always() }}
3436
run: docker compose -f test/cluster/cassandra/docker-compose.yml stop

.github/workflows/rust.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ jobs:
100100
- name: Run tests
101101
run: |
102102
RUST_LOG=trace SCYLLA_URI=172.42.0.2:9042 SCYLLA_URI2=172.42.0.3:9042 SCYLLA_URI3=172.42.0.4:9042 cargo test --features "full-serialization"
103+
- name: Check for stale test keyspaces
104+
run: SCYLLA_URI=172.42.0.2:9042 cargo run --bin find_stale_test_keyspaces
103105
- name: Stop the cluster
104106
if: ${{ always() }}
105107
run: docker compose -f test/cluster/docker-compose.yml stop

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"

scylla/src/client/caching_session.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,11 @@ mod tests {
482482
session
483483
}
484484

485+
async fn teardown_keyspace(session: &Session) {
486+
let ks = session.get_keyspace().unwrap();
487+
session.ddl(format!("DROP KEYSPACE {ks}")).await.unwrap();
488+
}
489+
485490
async fn create_caching_session() -> CachingSession {
486491
let session = CachingSession::from(new_for_test(true).await, 2);
487492

@@ -533,6 +538,8 @@ mod tests {
533538
let middle_query_removed = session.cache.get(middle_query).is_none();
534539

535540
assert!(first_query_removed || middle_query_removed);
541+
542+
teardown_keyspace(session.get_session()).await;
536543
}
537544

538545
/// Checks that the same prepared statement is reused when executing the same query twice
@@ -558,6 +565,8 @@ mod tests {
558565

559566
assert_eq!(1, session.cache.len());
560567
assert_eq!(1, result_rows.rows_num());
568+
569+
teardown_keyspace(session.get_session()).await;
561570
}
562571

563572
/// Checks that caching works with execute_iter
@@ -585,6 +594,8 @@ mod tests {
585594

586595
assert_eq!(1, rows);
587596
assert_eq!(1, session.cache.len());
597+
598+
teardown_keyspace(session.get_session()).await;
588599
}
589600

590601
/// Checks that caching works with execute_single_page
@@ -602,6 +613,8 @@ mod tests {
602613

603614
assert_eq!(1, session.cache.len());
604615
assert_eq!(1, result.into_rows_result().unwrap().rows_num());
616+
617+
teardown_keyspace(session.get_session()).await;
605618
}
606619

607620
async fn assert_test_batch_table_rows_contain(
@@ -653,12 +666,15 @@ mod tests {
653666
async fn test_custom_hasher() {
654667
setup_tracing();
655668

656-
let _session: CachingSession<std::collections::hash_map::RandomState> =
669+
let session: CachingSession<std::collections::hash_map::RandomState> =
657670
CachingSession::from(new_for_test(true).await, 2);
658-
let _session: CachingSession<CustomBuildHasher> =
671+
teardown_keyspace(session.get_session()).await;
672+
let session: CachingSession<CustomBuildHasher> =
659673
CachingSession::from(new_for_test(true).await, 2);
660-
let _session: CachingSession<CustomBuildHasher> =
674+
teardown_keyspace(session.get_session()).await;
675+
let session: CachingSession<CustomBuildHasher> =
661676
CachingSession::with_hasher(new_for_test(true).await, 2, Default::default());
677+
teardown_keyspace(session.get_session()).await;
662678
}
663679

664680
#[tokio::test]
@@ -775,6 +791,8 @@ mod tests {
775791
assert!(session.batch(&bad_batch, ((1, 2), (), (2,))).await.is_err());
776792
assert!(session.prepare_batch(&bad_batch).await.is_err());
777793
}
794+
795+
teardown_keyspace(session.get_session()).await;
778796
}
779797

780798
// The CachingSession::execute and friends should have the same StatementConfig
@@ -829,15 +847,15 @@ mod tests {
829847

830848
rows.sort_unstable();
831849
assert_eq!(rows, vec![(1, 1000), (2, 2000)]);
850+
851+
teardown_keyspace(session.get_session()).await;
832852
}
833853

834854
// Checks whether the PartitionerName is cached properly.
835855
#[tokio::test]
856+
#[cfg_attr(cassandra_tests, ignore)]
836857
async fn test_partitioner_name_caching() {
837858
setup_tracing();
838-
if option_env!("CDC") == Some("disabled") {
839-
return;
840-
}
841859

842860
// This test uses CDC which is not yet compatible with Scylla's tablets.
843861
let session: CachingSession = CachingSession::from(new_for_test(false).await, 100);
@@ -868,6 +886,8 @@ mod tests {
868886
// one can see which case failed by looking at the full backtrace
869887
verify_partitioner().await;
870888
verify_partitioner().await;
889+
890+
teardown_keyspace(session.get_session()).await;
871891
}
872892

873893
// NOTE: intentionally no `#[test]`: this is a compile-time test

scylla/src/network/connection.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,14 +2277,14 @@ mod tests {
22772277
let connection = Arc::new(connection);
22782278

22792279
let ks = unique_keyspace_name();
2280+
let session = SessionBuilder::new()
2281+
.known_node_addr(addr)
2282+
.build()
2283+
.await
2284+
.unwrap();
22802285

22812286
{
22822287
// Preparation phase
2283-
let session = SessionBuilder::new()
2284-
.known_node_addr(addr)
2285-
.build()
2286-
.await
2287-
.unwrap();
22882288
session.ddl(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks.clone())).await.unwrap();
22892289
session.use_keyspace(ks.clone(), false).await.unwrap();
22902290
session
@@ -2298,7 +2298,7 @@ mod tests {
22982298
}
22992299

23002300
connection
2301-
.use_keyspace(&super::VerifiedKeyspaceName::new(ks, false).unwrap())
2301+
.use_keyspace(&super::VerifiedKeyspaceName::new(ks.clone(), false).unwrap())
23022302
.await
23032303
.unwrap();
23042304

@@ -2357,6 +2357,11 @@ mod tests {
23572357
.await
23582358
.unwrap();
23592359
assert!(insert_res1.is_empty());
2360+
2361+
{
2362+
// Teardown phase
2363+
session.ddl(format!("DROP KEYSPACE {ks}")).await.unwrap();
2364+
}
23602365
}
23612366

23622367
#[tokio::test]
@@ -2377,13 +2382,14 @@ mod tests {
23772382
let addr: SocketAddr = resolve_hostname(&uri).await;
23782383
let ks = unique_keyspace_name();
23792384

2385+
let session = SessionBuilder::new()
2386+
.known_node_addr(addr)
2387+
.build()
2388+
.await
2389+
.unwrap();
2390+
23802391
{
23812392
// Preparation phase
2382-
let session = SessionBuilder::new()
2383-
.known_node_addr(addr)
2384-
.build()
2385-
.await
2386-
.unwrap();
23872393
session.ddl(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks.clone())).await.unwrap();
23882394
session.use_keyspace(ks.clone(), false).await.unwrap();
23892395
session
@@ -2484,6 +2490,11 @@ mod tests {
24842490
.await;
24852491
// No delay - coalescing disabled
24862492
subtest(None, ks.clone()).await;
2493+
2494+
{
2495+
// Teardown phase
2496+
session.ddl(format!("DROP KEYSPACE {ks} ")).await.unwrap();
2497+
}
24872498
}
24882499

24892500
// Returns the sum of integral numbers in the range [0..n)

scylla/tests/integration/ccm/authenticate.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ async fn authenticate_superuser_cluster_one_node() {
6060
let ks = unique_keyspace_name();
6161

6262
session.ddl(format!("CREATE KEYSPACE IF NOT EXISTS {ks} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}")).await.unwrap();
63-
session.use_keyspace(ks, false).await.unwrap();
63+
session.use_keyspace(&ks, false).await.unwrap();
6464
session.ddl("DROP TABLE IF EXISTS t;").await.unwrap();
65+
session.ddl(format!("DROP KEYSPACE {ks}")).await.unwrap();
6566

6667
tracing::info!("Ok.");
6768
}
@@ -124,8 +125,9 @@ async fn custom_authentication_cluster_one_node() {
124125
let ks = unique_keyspace_name();
125126

126127
session.ddl(format!("CREATE KEYSPACE IF NOT EXISTS {ks} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}")).await.unwrap();
127-
session.use_keyspace(ks, false).await.unwrap();
128+
session.use_keyspace(&ks, false).await.unwrap();
128129
session.ddl("DROP TABLE IF EXISTS t;").await.unwrap();
130+
session.ddl(format!("DROP KEYSPACE {ks}")).await.unwrap();
129131

130132
tracing::info!("Ok.");
131133
}

scylla/tests/integration/load_balancing/lwt_optimisation.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async fn if_lwt_optimisation_mark_offered_then_negotiatied_and_lwt_routed_optima
7777
create_ks += " and TABLETS = { 'enabled': false}";
7878
}
7979
session.ddl(create_ks).await.unwrap();
80-
session.use_keyspace(ks, false).await.unwrap();
80+
session.use_keyspace(&ks, false).await.unwrap();
8181

8282
session
8383
.ddl("CREATE TABLE t (a int primary key, b int)")
@@ -162,6 +162,8 @@ async fn if_lwt_optimisation_mark_offered_then_negotiatied_and_lwt_routed_optima
162162
assert_multiple_replicas_queried(&mut prepared_rxs);
163163
}
164164

165+
session.ddl(format!("DROP KEYSPACE {ks}")).await.unwrap();
166+
165167
running_proxy
166168
}).await;
167169

scylla/tests/integration/load_balancing/shards.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ async fn test_consistent_shard_awareness() {
8282
}
8383
}
8484

85+
session.ddl(format!("DROP KEYSPACE {ks}")).await.unwrap();
86+
8587
running_proxy
8688
}).await;
8789
match res {

scylla/tests/integration/load_balancing/simple_strategy.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,6 @@ async fn simple_strategy_test() {
5959
rows.sort();
6060

6161
assert_eq!(rows, vec![(1, 2, 3), (4, 5, 6), (7, 8, 9)]);
62+
63+
session.ddl(format!("DROP KEYSPACE {ks}")).await.unwrap();
6264
}

0 commit comments

Comments
 (0)