Skip to content

Commit 516a3db

Browse files
committed
feat: support serial run
Signed-off-by: Alex Chi <[email protected]>
1 parent 4a0a5f9 commit 516a3db

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

naivedb/src/bin/apply.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::path::Path;
22

33
use anyhow::Result;
4+
use sqlplannertest::PlannerTestApplyOptions;
45

56
#[tokio::main]
67
async fn main() -> Result<()> {

src/apply.rs

+25-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,25 @@ use crate::{
1010
discover_tests, parse_test_cases, ParsedTestCase, PlannerTestRunner, TestCase, RESULT_SUFFIX,
1111
};
1212

13+
#[derive(Default)]
14+
pub struct PlannerTestApplyOptions {
15+
pub serial: bool,
16+
}
17+
1318
pub async fn planner_test_apply<F, Ft, R>(path: impl AsRef<Path>, runner_fn: F) -> Result<()>
19+
where
20+
F: Fn() -> Ft + Send + Sync + 'static,
21+
Ft: Future<Output = Result<R>> + Send,
22+
R: PlannerTestRunner + 'static,
23+
{
24+
planner_test_apply_with_options(path, runner_fn, PlannerTestApplyOptions::default()).await
25+
}
26+
27+
pub async fn planner_test_apply_with_options<F, Ft, R>(
28+
path: impl AsRef<Path>,
29+
runner_fn: F,
30+
options: PlannerTestApplyOptions,
31+
) -> Result<()>
1432
where
1533
F: Fn() -> Ft + Send + Sync + 'static,
1634
Ft: Future<Output = Result<R>> + Send,
@@ -66,8 +84,13 @@ where
6684
.map_err(|e| (e, testname_x))
6785
});
6886

69-
let mut test_stream =
70-
test_stream.buffer_unordered(std::thread::available_parallelism()?.into());
87+
let mut test_stream = if options.serial {
88+
test_stream.then(|x| x).boxed()
89+
} else {
90+
test_stream
91+
.buffer_unordered(std::thread::available_parallelism()?.into())
92+
.boxed()
93+
};
7194

7295
let mut test_discovered = false;
7396
let mut failed_cases = vec![];

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod test_runner;
55
use std::path::Path;
66

77
use anyhow::{Context, Result};
8-
pub use apply::planner_test_apply;
8+
pub use apply::{planner_test_apply, planner_test_apply_with_options, PlannerTestApplyOptions};
99
use async_trait::async_trait;
1010
use glob::Paths;
1111
use resolve_id::resolve_testcase_id;

0 commit comments

Comments
 (0)