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

feat: integration test support env filter #811

Merged
merged 2 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ local-ip-address = "0.5"
reqwest = { workspace = true }
serde = { workspace = true }
sql = { workspace = true }
sqlness = "0.4.0"
sqlness = "0.4.3"
sqlparser = { workspace = true }
tokio = { workspace = true }
13 changes: 11 additions & 2 deletions integration_tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export CERESDB_CONFIG_FILE_0 ?= $(ROOT)/config/ceresdb-cluster-0.toml
export CERESDB_CONFIG_FILE_1 ?= $(ROOT)/config/ceresdb-cluster-1.toml
export CLUSTER_CERESDB_STDOUT_FILE_0 ?= /tmp/ceresdb-stdout-0.log
export CLUSTER_CERESDB_STDOUT_FILE_1 ?= /tmp/ceresdb-stdout-1.log
export RUST_BACKTRACE=1

clean:
rm -rf $(CERESDB_DATA_DIR) $(CERESDB_DATA_DIR_0) $(CERESDB_DATA_DIR_1) $(CERESMETA_DATA_DIR)
Expand All @@ -42,8 +43,16 @@ kill-old-process:
killall ceresdb-server | true
killall ceresmeta | true

run: clean build kill-old-process
RUST_BACKTRACE=1 $(CERESDB_TEST_BINARY)
prepare: clean build kill-old-process

run: prepare
$(CERESDB_TEST_BINARY)

run-local: prepare
CERESDB_ENV_FILTER=local $(CERESDB_TEST_BINARY)

run-cluster: prepare
CERESDB_ENV_FILTER=cluster $(CERESDB_TEST_BINARY)

run-java:
java -version
Expand Down
15 changes: 14 additions & 1 deletion integration_tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

## Running test

There exists a Makefile command to run integration test
There are three Makefile commands to run integration test:
```sh
# All envs
make run

# Only local env
make run-local

# Only cluster env
make run-cluster
```

`ceresdb-test` will recursively find all the files end with `.sql` and run it. Each file will be treated as a case. A file can contain multiple SQLs. When finished it will tell how many cases it run, and display the diff set if there is any. An example with one case:
Expand All @@ -14,6 +21,12 @@ Takes 49.020203ms. Diff: false. Test case "/home/ruihang/repo/CeresDB/tests/case
Run 1 finished. 0 cases are different.
```

Users can set `CERESDB_ENV_FILTER` variables to filter env to run. For example:
```
CERESDB_ENV_FILTER=local make run
```
This command will only run cases in `local`.

## Add a test

Please refer README of https://github.com/CeresDB/sqlness
Expand Down
7 changes: 5 additions & 2 deletions integration_tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::database::{CeresDBCluster, CeresDBServer};
mod database;

const CASE_ROOT_PATH_ENV: &str = "CERESDB_TEST_CASE_PATH";
const ENV_FILTER_ENV: &str = "CERESDB_ENV_FILTER";

struct CeresDBController;
struct UntypedCeresDB {
Expand Down Expand Up @@ -62,12 +63,14 @@ impl EnvController for CeresDBController {
#[tokio::main]
async fn main() -> Result<()> {
let case_dir = env::var(CASE_ROOT_PATH_ENV)?;
let env = CeresDBController;
let env_filter = env::var(ENV_FILTER_ENV).unwrap_or_else(|_| ".*".to_string());
let controller = CeresDBController;
let config = sqlness::ConfigBuilder::default()
.case_dir(case_dir)
.env_filter(env_filter)
.follow_links(true)
.build()?;
let runner = Runner::new_with_config(config, env).await?;
let runner = Runner::new_with_config(config, controller).await?;
runner.run().await?;

Ok(())
Expand Down