From d0b2a11f2b7d726e02b86d2601311c842df11538 Mon Sep 17 00:00:00 2001 From: Ruihang Xia Date: Mon, 22 Apr 2024 17:21:37 +0800 Subject: [PATCH] feat: add preserve arg to sqlness runner (#3724) * feat: add preserve arg to sqlness runner Signed-off-by: Ruihang Xia * replace tempdir with tempfile Signed-off-by: Ruihang Xia --------- Signed-off-by: Ruihang Xia --- .github/workflows/develop.yml | 8 ++++---- Cargo.lock | 1 + tests/runner/Cargo.toml | 1 + tests/runner/src/main.rs | 19 +++++++++++++++---- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index 626decd81a..753750ecda 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -184,13 +184,13 @@ jobs: - name: Unzip binaries run: tar -xvf ./bins.tar.gz - name: Run sqlness - run: RUST_BACKTRACE=1 ./bins/sqlness-runner -c ./tests/cases --bins-dir ./bins + run: RUST_BACKTRACE=1 ./bins/sqlness-runner -c ./tests/cases --bins-dir ./bins --preserve-state - name: Upload sqlness logs if: always() uses: actions/upload-artifact@v4 with: name: sqlness-logs - path: /tmp/greptime-*.log + path: /tmp/sqlness-* retention-days: 3 sqlness-kafka-wal: @@ -214,13 +214,13 @@ jobs: working-directory: tests-integration/fixtures/kafka run: docker compose -f docker-compose-standalone.yml up -d --wait - name: Run sqlness - run: RUST_BACKTRACE=1 ./bins/sqlness-runner -w kafka -k 127.0.0.1:9092 -c ./tests/cases --bins-dir ./bins + run: RUST_BACKTRACE=1 ./bins/sqlness-runner -w kafka -k 127.0.0.1:9092 -c ./tests/cases --bins-dir ./bins --preserve-state - name: Upload sqlness logs if: always() uses: actions/upload-artifact@v4 with: name: sqlness-logs-with-kafka-wal - path: /tmp/greptime-*.log + path: /tmp/sqlness-* retention-days: 3 fmt: diff --git a/Cargo.lock b/Cargo.lock index df319a7e2a..43de72832e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9539,6 +9539,7 @@ dependencies = [ "serde", "serde_json", "sqlness", + "tempfile", "tinytemplate", "tokio", ] diff --git a/tests/runner/Cargo.toml b/tests/runner/Cargo.toml index adf4df8093..6e8848de5c 100644 --- a/tests/runner/Cargo.toml +++ b/tests/runner/Cargo.toml @@ -18,5 +18,6 @@ common-time.workspace = true serde.workspace = true serde_json.workspace = true sqlness = { version = "0.5" } +tempfile.workspace = true tinytemplate = "1.2" tokio.workspace = true diff --git a/tests/runner/src/main.rs b/tests/runner/src/main.rs index 415672a759..cf2d9fd7e0 100644 --- a/tests/runner/src/main.rs +++ b/tests/runner/src/main.rs @@ -67,16 +67,22 @@ struct Args { /// If not set, sqlness will build GreptimeDB on the fly. #[clap(long)] bins_dir: Option, + + /// Preserve persistent state in the temporary directory. + /// This may affect future test runs. + #[clap(long)] + preserve_state: bool, } #[tokio::main] async fn main() { let args = Args::parse(); - #[cfg(windows)] - let data_home = std::env::temp_dir(); - #[cfg(not(windows))] - let data_home = std::path::PathBuf::from("/tmp"); + let temp_dir = tempfile::Builder::new() + .prefix("sqlness") + .tempdir() + .unwrap(); + let data_home = temp_dir.path().to_path_buf(); let config = ConfigBuilder::default() .case_dir(util::get_case_dir(args.case_dir)) @@ -104,4 +110,9 @@ async fn main() { Env::new(data_home, args.server_addr, wal, args.bins_dir), ); runner.run().await.unwrap(); + + // skip clean up and exit + if args.preserve_state { + println!("Preserving state in {:?}", temp_dir.into_path()); + } }