Skip to content

Commit

Permalink
Merge pull request #1060 from wprzytula/fix-counter-tests-not-to-use-…
Browse files Browse the repository at this point in the history
…tablets

tests: disable tablets in CQL Counter's tests
  • Loading branch information
Lorak-mmk authored Aug 21, 2024
2 parents 0093431 + 35832d9 commit bac7f9e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
41 changes: 26 additions & 15 deletions scylla/src/transport/cql_types_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::cql_to_rust::FromCqlVal;
use crate::frame::response::result::CqlValue;
use crate::frame::value::{Counter, CqlDate, CqlTime, CqlTimestamp};
use crate::macros::FromUserType;
use crate::test_utils::{create_new_session_builder, setup_tracing};
use crate::test_utils::{create_new_session_builder, scylla_supports_tablets, setup_tracing};
use crate::transport::session::Session;
use crate::utils::test_utils::unique_keyspace_name;
use itertools::Itertools;
Expand All @@ -16,23 +16,27 @@ use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::str::FromStr;

// Used to prepare a table for test
// Creates a new keyspace
// Creates a new keyspace, without tablets if requested and the ScyllaDB instance supports them.
// Drops and creates table {table_name} (id int PRIMARY KEY, val {type_name})
async fn init_test(table_name: &str, type_name: &str) -> Session {
async fn init_test_maybe_without_tablets(
table_name: &str,
type_name: &str,
supports_tablets: bool,
) -> Session {
let session: Session = create_new_session_builder().build().await.unwrap();
let ks = unique_keyspace_name();

session
.query(
format!(
"CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = \
{{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}",
ks
),
&[],
)
.await
.unwrap();
let mut create_ks = format!(
"CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = \
{{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}",
ks
);

if !supports_tablets && scylla_supports_tablets(&session).await {
create_ks += " AND TABLETS = {'enabled': false}"
}

session.query(create_ks, &[]).await.unwrap();
session.use_keyspace(ks, false).await.unwrap();

session
Expand All @@ -54,6 +58,13 @@ async fn init_test(table_name: &str, type_name: &str) -> Session {
session
}

// Used to prepare a table for test
// Creates a new keyspace
// Drops and creates table {table_name} (id int PRIMARY KEY, val {type_name})
async fn init_test(table_name: &str, type_name: &str) -> Session {
init_test_maybe_without_tablets(table_name, type_name, true).await
}

// This function tests serialization and deserialization mechanisms by sending insert and select
// queries to running Scylla instance.
// To do so, it:
Expand Down Expand Up @@ -267,7 +278,7 @@ async fn test_counter() {

// Can't use run_tests, because counters are special and can't be inserted
let type_name = "counter";
let session: Session = init_test(type_name, type_name).await;
let session: Session = init_test_maybe_without_tablets(type_name, type_name, false).await;

for (i, test) in tests.iter().enumerate() {
let update_bound_value = format!("UPDATE {} SET val = val + ? WHERE id = ?", type_name);
Expand Down
9 changes: 8 additions & 1 deletion scylla/src/transport/session_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,14 @@ async fn test_counter_batch() {
let session = Arc::new(create_new_session_builder().build().await.unwrap());
let ks = unique_keyspace_name();

session.query(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks), &[]).await.unwrap();
// Need to disable tablets in this test because they don't support counters yet.
// (https://github.com/scylladb/scylladb/commit/c70f321c6f581357afdf3fd8b4fe8e5c5bb9736e).
let mut create_ks = format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks);
if scylla_supports_tablets(&session).await {
create_ks += " AND TABLETS = {'enabled': false}"
}

session.query(create_ks, &[]).await.unwrap();
session
.query(
format!(
Expand Down

0 comments on commit bac7f9e

Please sign in to comment.