Skip to content

Commit

Permalink
test: add e2e tests for read-only transaction in multiple sessions (#…
Browse files Browse the repository at this point in the history
…10902)

Signed-off-by: Bugen Zhao <i@bugenzhao.com>
  • Loading branch information
BugenZhao authored and kwannoel committed Jul 14, 2023
1 parent 3b92547 commit b21fa4d
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 66 deletions.
114 changes: 68 additions & 46 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ description = "Kill cluster, dump logs and check logs"

[tasks.slt]
category = "RiseDev - SQLLogicTest"
install_crate = { version = "0.14.0", crate_name = "sqllogictest-bin", binary = "sqllogictest", test_arg = [
install_crate = { version = "0.15.0", crate_name = "sqllogictest-bin", binary = "sqllogictest", test_arg = [
"--help",
] }
command = "sqllogictest"
Expand Down
2 changes: 1 addition & 1 deletion ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
RUN cargo binstall -y --no-symlinks cargo-llvm-cov cargo-nextest cargo-udeps cargo-hakari cargo-sort cargo-make@0.36.10 cargo-cache cargo-audit \
&& cargo install sccache --locked \
&& cargo install sqllogictest-bin@0.14.0 \
&& cargo install sqllogictest-bin@0.15.0 \
&& cargo cache -a \
&& rm -rf "/root/.cargo/registry/index" \
&& rm -rf "/root/.cargo/registry/cache" \
Expand Down
2 changes: 1 addition & 1 deletion ci/build-ci-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cat ../rust-toolchain
# !!! CHANGE THIS WHEN YOU WANT TO BUMP CI IMAGE !!! #
# AND ALSO docker-compose.yml #
######################################################
export BUILD_ENV_VERSION=v20230702
export BUILD_ENV_VERSION=v20230712

export BUILD_TAG="public.ecr.aws/x5u3w5h6/rw-build-env:${BUILD_ENV_VERSION}"

Expand Down
10 changes: 5 additions & 5 deletions ci/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ services:
retries: 5

source-test-env:
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20230702
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20230712
depends_on:
- mysql
- db
Expand All @@ -79,7 +79,7 @@ services:
- ..:/risingwave

sink-test-env:
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20230702
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20230712
depends_on:
- mysql
- db
Expand All @@ -88,12 +88,12 @@ services:
- ..:/risingwave

rw-build-env:
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20230702
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20230712
volumes:
- ..:/risingwave

ci-flamegraph-env:
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20230702
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20230712
# NOTE(kwannoel): This is used in order to permit
# syscalls for `nperf` (perf_event_open),
# so it can do CPU profiling.
Expand All @@ -104,7 +104,7 @@ services:
- ..:/risingwave

regress-test-env:
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20230702
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20230712
depends_on:
db:
condition: service_healthy
Expand Down
64 changes: 64 additions & 0 deletions e2e_test/batch/transaction/read_only_multi_conn.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
statement ok
create table t (v int);

statement ok
insert into t values (1), (2);

statement ok
flush;

statement ok
start transaction read only;

query I
select count(*) from t;
----
2

connection other
query I
select count(*) from t;
----
2

connection other
statement ok
insert into t values (3);

connection other
statement ok
flush;

# inserts are visible in the `other` connection,
connection other
query I
select count(*) from t;
----
3

# ...but not in the read-only transaction
query I
select count(*) from t;
----
2

statement ok
flush;

# still invisible even after flush
query I
select count(*) from t;
----
2

statement ok
commit;

# now visible outside the transaction
query I
select count(*) from t;
----
3

statement ok
drop table t;
2 changes: 1 addition & 1 deletion src/tests/simulation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ risingwave_sqlsmith = { path = "../sqlsmith" }
serde = "1.0.152"
serde_derive = "1.0.152"
serde_json = "1.0.91"
sqllogictest = "0.11.1"
sqllogictest = "0.15.0"
tempfile = "3"
tokio = { version = "0.2.19", package = "madsim-tokio" }
tokio-postgres = "0.7"
Expand Down
8 changes: 5 additions & 3 deletions src/tests/simulation/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use itertools::Itertools;
use lru::{Iter, LruCache};
use risingwave_sqlparser::ast::Statement;
use risingwave_sqlparser::parser::Parser;
use sqllogictest::{DBOutput, DefaultColumnType};

/// A RisingWave client.
pub struct RisingWave {
Expand Down Expand Up @@ -160,10 +161,11 @@ impl Drop for RisingWave {

#[async_trait::async_trait]
impl sqllogictest::AsyncDB for RisingWave {
type ColumnType = DefaultColumnType;
type Error = tokio_postgres::error::Error;

async fn run(&mut self, sql: &str) -> Result<sqllogictest::DBOutput, Self::Error> {
use sqllogictest::{ColumnType, DBOutput};
async fn run(&mut self, sql: &str) -> Result<DBOutput<Self::ColumnType>, Self::Error> {
use sqllogictest::DBOutput;

if self.client.is_closed() {
// connection error, reset the client
Expand Down Expand Up @@ -208,7 +210,7 @@ impl sqllogictest::AsyncDB for RisingWave {
Ok(DBOutput::StatementComplete(cnt))
} else {
Ok(DBOutput::Rows {
types: vec![ColumnType::Any; output[0].len()],
types: vec![DefaultColumnType::Any; output[0].len()],
rows: output,
})
}
Expand Down
13 changes: 5 additions & 8 deletions src/tests/simulation/src/slt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const KILL_IGNORE_FILES: &[&str] = &[
// Drop is not retryable in search path test.
"search_path.slt",
// Transaction statements are not retryable.
"transaction/read_only_multi_conn.slt",
"transaction/read_only.slt",
"transaction/tolerance.slt",
];
Expand All @@ -98,10 +99,8 @@ pub async fn run_slt_task(cluster: Arc<Cluster>, glob: &str, opts: &KillOpts) {
let files = glob::glob(glob).expect("failed to read glob pattern");
for file in files {
// use a session per file
let risingwave = RisingWave::connect("frontend".into(), "dev".into())
.await
.unwrap();
let mut tester = sqllogictest::Runner::new(risingwave);
let mut tester =
sqllogictest::Runner::new(|| RisingWave::connect("frontend".into(), "dev".into()));

let file = file.unwrap();
let path = file.as_path();
Expand Down Expand Up @@ -229,10 +228,8 @@ pub async fn run_slt_task(cluster: Arc<Cluster>, glob: &str, opts: &KillOpts) {
}

pub async fn run_parallel_slt_task(glob: &str, jobs: usize) -> Result<(), ParallelTestError> {
let db = RisingWave::connect("frontend".into(), "dev".into())
.await
.unwrap();
let mut tester = sqllogictest::Runner::new(db);
let mut tester =
sqllogictest::Runner::new(|| RisingWave::connect("frontend".into(), "dev".into()));
tester
.run_parallel_async(
glob,
Expand Down
2 changes: 2 additions & 0 deletions src/workspace-hack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ rand = { version = "0.8", features = ["small_rng"] }
rand_chacha = { version = "0.3" }
rand_core = { version = "0.6", default-features = false, features = ["std"] }
regex = { version = "1" }
regex-automata = { version = "0.3", default-features = false, features = ["dfa-onepass", "hybrid", "meta", "nfa-backtrack", "perf-inline", "perf-literal", "unicode"] }
regex-syntax = { version = "0.7" }
reqwest = { version = "0.11", features = ["blocking", "json", "rustls-tls"] }
rust_decimal = { version = "1", features = ["db-postgres", "maths"] }
Expand Down Expand Up @@ -163,6 +164,7 @@ rand = { version = "0.8", features = ["small_rng"] }
rand_chacha = { version = "0.3" }
rand_core = { version = "0.6", default-features = false, features = ["std"] }
regex = { version = "1" }
regex-automata = { version = "0.3", default-features = false, features = ["dfa-onepass", "hybrid", "meta", "nfa-backtrack", "perf-inline", "perf-literal", "unicode"] }
regex-syntax = { version = "0.7" }
reqwest = { version = "0.11", features = ["blocking", "json", "rustls-tls"] }
rust_decimal = { version = "1", features = ["db-postgres", "maths"] }
Expand Down

0 comments on commit b21fa4d

Please sign in to comment.