Skip to content

Commit e32c7fa

Browse files
committed
fix: reuse configuration in run_parallel
Signed-off-by: Bugen Zhao <[email protected]>
1 parent 3665b1d commit e32c7fa

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

Diff for: sqllogictest/src/connection.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ where
3434
}
3535

3636
/// Connections established in a [`Runner`](crate::Runner).
37+
#[derive(Clone)]
3738
pub(crate) struct Connections<D, M> {
3839
make_conn: M,
3940
conns: HashMap<ConnectionName, D>,

Diff for: sqllogictest/src/runner.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,8 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
649649
};
650650

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

10911092
/// accept the tasks, spawn jobs task to run slt test. the tasks are (AsyncDB, slt filename)
10921093
/// pairs.
1094+
// TODO: This is not a good interface, as the `make_conn` passed to `new` is unused but we
1095+
// accept a new `conn_builder` here. May change `MakeConnection` to support specifying the
1096+
// database name in the future.
10931097
pub async fn run_parallel_async<Fut>(
10941098
&mut self,
10951099
glob: &str,
@@ -1115,9 +1119,20 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
11151119
.await
11161120
.expect("create db failed");
11171121
let target = hosts[idx % hosts.len()].clone();
1122+
1123+
let mut tester = Runner {
1124+
conn: Connections::new(move || {
1125+
conn_builder(target.clone(), db_name.clone()).map(Ok)
1126+
}),
1127+
validator: self.validator,
1128+
column_type_validator: self.column_type_validator,
1129+
substitution: self.substitution.clone(),
1130+
sort_mode: self.sort_mode,
1131+
hash_threshold: self.hash_threshold,
1132+
labels: self.labels.clone(),
1133+
};
1134+
11181135
tasks.push(async move {
1119-
let mut tester =
1120-
Runner::new(move || conn_builder(target.clone(), db_name.clone()).map(Ok));
11211136
let filename = file.to_string_lossy().to_string();
11221137
tester.run_file_async(filename).await
11231138
})

Diff for: sqllogictest/src/substitution.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
use std::sync::OnceLock;
1+
use std::sync::{Arc, OnceLock};
22

33
use subst::Env;
44
use tempfile::{tempdir, TempDir};
55

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

1414
impl<'a> subst::VariableMap<'a> for Substitution {

0 commit comments

Comments
 (0)