Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add integration tests for batch statements #1226

Open
wants to merge 3 commits into
base: branch-hackathon
Choose a base branch
from

Conversation

dimakr
Copy link

@dimakr dimakr commented Feb 11, 2025

Test cases/ideas are inspired by Java driver batch statements tests.

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • I added relevant tests for new features and bug fixes.
  • All commits compile, pass static checks and pass test.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have provided docstrings for the public items that I want to introduce.
  • I have adjusted the documentation in ./docs/source/.
  • I added appropriate Fixes: annotations to PR description.

Copy link

github-actions bot commented Feb 11, 2025

cargo semver-checks found no API-breaking changes in this PR! 🎉🥳
Checked commit: fc9def4

@dimakr dimakr force-pushed the session_batch_tests branch from e8fb95f to b5b6185 Compare February 11, 2025 14:27
@dimakr dimakr marked this pull request as ready for review February 11, 2025 15:17
@wprzytula
Copy link
Collaborator

I intended to open a PR instead of pushing to your branch directly, sorry @dimakr...

scylla/tests/integration/main.rs Outdated Show resolved Hide resolved
scylla/tests/integration/batch_statements.rs Outdated Show resolved Hide resolved
scylla/tests/integration/batch_statements.rs Outdated Show resolved Hide resolved
@dimakr dimakr force-pushed the session_batch_tests branch from ca37183 to 947c483 Compare February 11, 2025 21:42
@dimakr
Copy link
Author

dimakr commented Feb 11, 2025

@wprzytula I've made the changes as per the comments above

@dimakr dimakr requested a review from wprzytula February 12, 2025 09:47
@dimakr dimakr force-pushed the session_batch_tests branch from 947c483 to bd00e4b Compare February 12, 2025 17:12
@dimakr
Copy link
Author

dimakr commented Feb 12, 2025

Turned out that we have a few batch tests in scylla/tests/integration/session.rs test suite.
Moved them to the dedicated batch.rs test suite, for which we are creating new test cases in this PR.

@dimakr dimakr requested a review from wprzytula February 12, 2025 22:56
@dimakr dimakr self-assigned this Feb 12, 2025
scylla/tests/common/utils.rs Outdated Show resolved Hide resolved
scylla/tests/integration/batch_statements.rs Outdated Show resolved Hide resolved
scylla/tests/integration/batch_statements.rs Outdated Show resolved Hide resolved
Comment on lines 276 to 269
/// TODO: Remove #[ignore] once LWTs are supported with tablets.
#[tokio::test]
#[ignore]
async fn test_cas_batch() {
setup_tracing();
let test_name = String::from("test_cas_batch");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you got the inspiration from test_lwt_optimization_works_with_tablets. The difference is that this test does not depend on tablets, while test_lwt_optimization_works_with_tablets does.
Please disable tablets explicitly during keyspace creation. This will allow the test to actually run.

scylla/tests/integration/batch_statements.rs Outdated Show resolved Hide resolved
scylla/tests/integration/batch_statements.rs Outdated Show resolved Hide resolved
scylla/tests/integration/batch_statements.rs Outdated Show resolved Hide resolved
scylla/tests/common/utils.rs Outdated Show resolved Hide resolved
@dimakr dimakr force-pushed the session_batch_tests branch from 6ec6b38 to c53c53b Compare February 13, 2025 12:08
scylla/tests/integration/batch.rs Outdated Show resolved Hide resolved
scylla/tests/integration/batch.rs Outdated Show resolved Hide resolved
scylla/tests/integration/batch.rs Outdated Show resolved Hide resolved
Comment on lines 509 to 520
// Scylla returns 4 columns, but Cassandra returns only 1
let is_scylla: bool = batch_deserializer.column_specs().len() == 4;

if is_scylla {
test_batch_lwts_for_scylla(&session, &batch, &batch_deserializer, &test_name).await;
} else {
test_batch_lwts_for_cassandra(&session, &batch, &batch_deserializer, &test_name).await;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 Please provide links to documentation explaining this difference.

@dimakr dimakr force-pushed the session_batch_tests branch from c53c53b to 2c7d920 Compare February 13, 2025 14:52
@dimakr
Copy link
Author

dimakr commented Feb 13, 2025

@wprzytula @Lorak-mmk addressed the last comments.

@Lorak-mmk
Copy link
Collaborator

@wprzytula @Lorak-mmk addressed the last comments.

In commit "tests: add integration tests for batch statements" some tests are still marked with #[ignore] instead of disabling tablets. Maybe you forgot to fix that?

Comment on lines 42 to 45
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs(),
.as_micros(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why this change is necessary.
Notice that the keyspace name also utilizes the global counter.
The only way I see to acutally get a collision is to have 2 copies of the repository, run the same test in both, and be extremely unlucky for them to clash both on the counter and the timestamp. This seems extremely unlikely.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how the batch tests fail. if as_sec() is used to generate suffix for KS name:

──── STDERR:             scylla::integration batch::test_batch_lwts
thread 'batch::test_batch_lwts' panicked at scylla/tests/integration/batch.rs:506:76:
called `Result::unwrap()` on an `Err` value: LastAttemptError(DbError(Invalid, "Cannot use LightWeight Transactions for table test_rust_1739527888_0.test_counter_batch: LWT is not yet supported with tablets"))
...
──── STDERR:             scylla::integration batch::test_fail_counter_batch_with_non_counter_increment
thread 'batch::test_fail_counter_batch_with_non_counter_increment' panicked at scylla/tests/integration/batch.rs:54:14:
called `Result::unwrap()` on an `Err` value: LastAttemptError(DbError(Invalid, "Cannot use the 'counter' type for table test_rust_1739527888_0.counter1: Counters are not yet supported with tablets"))
...

The batch test suite uses the common helper to create a KS and table. Then when each test is executed and calls the helper it would try to get its own, unique, KS name. But tests in this test suite are executed within 1 second so the unique_keyspace_name cannot guarantee unique value. And in this particular test suite part of tests require KS with tablets disabled, so the existing KS cannot be reused.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably for the affected tests here some other approach could be used, i.e. do not useunique_keyspace_name, but some dedicated KS name generation logic. But I thought that the symptom might pop up in other tests as well, and this change would help.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But tests in this test suite are executed within 1 second so the unique_keyspace_name cannot guarantee unique value.

Please the the source code of unique_keyspace_name. It uses an atomic counter to guarantee uniqueness.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

──── STDERR:             scylla::integration batch::test_batch_lwts
thread 'batch::test_batch_lwts' panicked at scylla/tests/integration/batch.rs:506:76:
called `Result::unwrap()` on an `Err` value: LastAttemptError(DbError(Invalid, "Cannot use LightWeight Transactions for table test_rust_1739527888_0.test_counter_batch: LWT is not yet supported with tablets"))
...
──── STDERR:             scylla::integration batch::test_fail_counter_batch_with_non_counter_increment
thread 'batch::test_fail_counter_batch_with_non_counter_increment' panicked at scylla/tests/integration/batch.rs:54:14:
called `Result::unwrap()` on an `Err` value: LastAttemptError(DbError(Invalid, "Cannot use the 'counter' type for table test_rust_1739527888_0.counter1: Counters are not yet supported with tablets"))
...

Weird, the counter is 0 for both of them. How are you running the tests?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fails when specific module is executed, e.g.:

> cargo nextest r -E 'test(/^batch::/)'

But it is ok when all tests are executed at once (make test, etc.). So I'll drop that change.

Copy link
Collaborator

@Lorak-mmk Lorak-mmk Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo nextest is not something we ever tested, nor recommended in CONTRIBUTING.md.
It uses process-per-test architecture, making a counter that guarantees uniqueness useless - because each process, and thus test, will have its own copy of it, thus always using 0.

@dimakr dimakr force-pushed the session_batch_tests branch from 2c7d920 to 6974ed0 Compare February 14, 2025 10:42
@dimakr
Copy link
Author

dimakr commented Feb 14, 2025

In commit "tests: add integration tests for batch statements" some tests are still marked with #[ignore] instead of disabling tablets. Maybe you forgot to fix that?

@Lorak-mmk the tablets disabling was done as part of "tests: move batch statements tests to batch.rs module" commit. I've adjusted that commit message to clearly mention this.

@dimakr dimakr requested a review from Lorak-mmk February 14, 2025 10:46
@Lorak-mmk
Copy link
Collaborator

Lorak-mmk commented Feb 14, 2025

@Lorak-mmk the tablets disabling was done as part of "tests: move batch statements tests to batch.rs module" commit. I've adjusted that commit message to clearly mention this.

Is there a reason for doing it in the commit that moves tests, instead of doing it that way from the beginning?

@dimakr dimakr force-pushed the session_batch_tests branch from 6974ed0 to 650ec58 Compare February 14, 2025 11:48
@dimakr
Copy link
Author

dimakr commented Feb 14, 2025

Is there a reason for doing it in the commit that moves tests, instead of doing it that way from the beginning?

There was a bit of mess in the series of commits in this PR from the beginning after a commit from another person was accidentally pushed in (that one is squashed eventually). But to avoid further issues I've made 'disable tablets'-change in the subsequent commit.

@Lorak-mmk
Copy link
Collaborator

Lorak-mmk commented Feb 14, 2025

Two things:

  • I don't think you fixed all tests in regards to tablets. In the "Files changed view" I see that test_cas_batch, test_counter_batch, test_fail_logged_batch_with_counter_increment, test_fail_counter_batch_with_non_counter_increment in batch_statement.rs are still ignored.
  • I see that after this PR we have 2 files: batch.rs and batch_statement.rs. Why? What future tests should go into the latter, and what into the former?

@dimakr
Copy link
Author

dimakr commented Feb 14, 2025

Two things:

It was OK, but due to this number of nit related changes one of recent rebases went wrong. Will correct it

New batch statement test cases are moved to exising batch.rs test suite.

Additionally, the test cases for LWT and counter tables are unskipped
and adjusted to use keyspace with tablets disabled. This allows executing
the underlying test scenarios even though LWT and counters are not yet
supported with tablets.
@dimakr dimakr force-pushed the session_batch_tests branch from 650ec58 to fc9def4 Compare February 14, 2025 16:09
@dimakr
Copy link
Author

dimakr commented Feb 14, 2025

Two things:

It was OK, but due to this number of nit related changes one of recent rebases went wrong. Will correct it

@Lorak-mmk This time should be ok - got rid of batch_statement.rs as per comment #1226 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants