Skip to content

Commit

Permalink
fix: inherit configuration in run_parallel (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
BugenZhao authored Jun 20, 2024
1 parent 3665b1d commit da5ef94
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-semver-checks --version ^0.27 --locked
args: cargo-semver-checks --version ^0.32 --locked
- name: Check semver
run: |
cargo semver-checks check-release -p sqllogictest
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [0.20.5] - 2024-06-20

* fix(runner): when running in parallel, the runner will correctly inherit configuration like `sort_mode` and `labels` from the main runner.

## [0.20.4] - 2024-06-06

* bump dependencies
Expand Down
6 changes: 3 additions & 3 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = ["sqllogictest", "sqllogictest-bin", "sqllogictest-engines", "tests"]

[workspace.package]
version = "0.20.4"
version = "0.20.5"
edition = "2021"
homepage = "https://github.com/risinglightdb/sqllogictest-rs"
keywords = ["sql", "database", "parser", "cli"]
Expand Down
21 changes: 18 additions & 3 deletions sqllogictest/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,8 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
};

if is_background {
// Spawn a new process, but don't wait for stdout, otherwise it will block until the process exits.
// Spawn a new process, but don't wait for stdout, otherwise it will block until
// the process exits.
let error: Option<AnyError> = match cmd.spawn() {
Ok(_) => None,
Err(e) => Some(Arc::new(e)),
Expand Down Expand Up @@ -1090,6 +1091,9 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {

/// accept the tasks, spawn jobs task to run slt test. the tasks are (AsyncDB, slt filename)
/// pairs.
// TODO: This is not a good interface, as the `make_conn` passed to `new` is unused but we
// accept a new `conn_builder` here. May change `MakeConnection` to support specifying the
// database name in the future.
pub async fn run_parallel_async<Fut>(
&mut self,
glob: &str,
Expand All @@ -1115,9 +1119,20 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
.await
.expect("create db failed");
let target = hosts[idx % hosts.len()].clone();

let mut tester = Runner {
conn: Connections::new(move || {
conn_builder(target.clone(), db_name.clone()).map(Ok)
}),
validator: self.validator,
column_type_validator: self.column_type_validator,
substitution: self.substitution.clone(),
sort_mode: self.sort_mode,
hash_threshold: self.hash_threshold,
labels: self.labels.clone(),
};

tasks.push(async move {
let mut tester =
Runner::new(move || conn_builder(target.clone(), db_name.clone()).map(Ok));
let filename = file.to_string_lossy().to_string();
tester.run_file_async(filename).await
})
Expand Down
6 changes: 3 additions & 3 deletions sqllogictest/src/substitution.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::sync::OnceLock;
use std::sync::{Arc, OnceLock};

use subst::Env;
use tempfile::{tempdir, TempDir};

/// Substitute environment variables and special variables like `__TEST_DIR__` in SQL.
#[derive(Default)]
#[derive(Default, Clone)]
pub(crate) struct Substitution {
/// The temporary directory for `__TEST_DIR__`.
/// Lazily initialized and cleaned up when dropped.
test_dir: OnceLock<TempDir>,
test_dir: Arc<OnceLock<TempDir>>,
}

impl<'a> subst::VariableMap<'a> for Substitution {
Expand Down

0 comments on commit da5ef94

Please sign in to comment.