From 516a3dbda10f969e403593c2c00eb5c033f3abd2 Mon Sep 17 00:00:00 2001 From: Alex Chi Date: Sat, 2 Nov 2024 01:23:24 -0400 Subject: [PATCH 1/2] feat: support serial run Signed-off-by: Alex Chi --- naivedb/src/bin/apply.rs | 1 + src/apply.rs | 27 +++++++++++++++++++++++++-- src/lib.rs | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/naivedb/src/bin/apply.rs b/naivedb/src/bin/apply.rs index 85c3b30..ae6712f 100644 --- a/naivedb/src/bin/apply.rs +++ b/naivedb/src/bin/apply.rs @@ -1,6 +1,7 @@ use std::path::Path; use anyhow::Result; +use sqlplannertest::PlannerTestApplyOptions; #[tokio::main] async fn main() -> Result<()> { diff --git a/src/apply.rs b/src/apply.rs index 9d83900..eda959e 100644 --- a/src/apply.rs +++ b/src/apply.rs @@ -10,7 +10,25 @@ use crate::{ discover_tests, parse_test_cases, ParsedTestCase, PlannerTestRunner, TestCase, RESULT_SUFFIX, }; +#[derive(Default)] +pub struct PlannerTestApplyOptions { + pub serial: bool, +} + pub async fn planner_test_apply(path: impl AsRef, runner_fn: F) -> Result<()> +where + F: Fn() -> Ft + Send + Sync + 'static, + Ft: Future> + Send, + R: PlannerTestRunner + 'static, +{ + planner_test_apply_with_options(path, runner_fn, PlannerTestApplyOptions::default()).await +} + +pub async fn planner_test_apply_with_options( + path: impl AsRef, + runner_fn: F, + options: PlannerTestApplyOptions, +) -> Result<()> where F: Fn() -> Ft + Send + Sync + 'static, Ft: Future> + Send, @@ -66,8 +84,13 @@ where .map_err(|e| (e, testname_x)) }); - let mut test_stream = - test_stream.buffer_unordered(std::thread::available_parallelism()?.into()); + let mut test_stream = if options.serial { + test_stream.then(|x| x).boxed() + } else { + test_stream + .buffer_unordered(std::thread::available_parallelism()?.into()) + .boxed() + }; let mut test_discovered = false; let mut failed_cases = vec![]; diff --git a/src/lib.rs b/src/lib.rs index 09a4599..0eef0b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,7 @@ mod test_runner; use std::path::Path; use anyhow::{Context, Result}; -pub use apply::planner_test_apply; +pub use apply::{planner_test_apply, planner_test_apply_with_options, PlannerTestApplyOptions}; use async_trait::async_trait; use glob::Paths; use resolve_id::resolve_testcase_id; From 4e42b52ebc3008857742a480090d26a3f9b63ec8 Mon Sep 17 00:00:00 2001 From: Alex Chi Date: Sat, 2 Nov 2024 01:25:56 -0400 Subject: [PATCH 2/2] fix Signed-off-by: Alex Chi --- naivedb/src/bin/apply.rs | 1 - src/apply.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/naivedb/src/bin/apply.rs b/naivedb/src/bin/apply.rs index ae6712f..85c3b30 100644 --- a/naivedb/src/bin/apply.rs +++ b/naivedb/src/bin/apply.rs @@ -1,7 +1,6 @@ use std::path::Path; use anyhow::Result; -use sqlplannertest::PlannerTestApplyOptions; #[tokio::main] async fn main() -> Result<()> { diff --git a/src/apply.rs b/src/apply.rs index eda959e..a3267f3 100644 --- a/src/apply.rs +++ b/src/apply.rs @@ -10,7 +10,7 @@ use crate::{ discover_tests, parse_test_cases, ParsedTestCase, PlannerTestRunner, TestCase, RESULT_SUFFIX, }; -#[derive(Default)] +#[derive(Default, Clone)] pub struct PlannerTestApplyOptions { pub serial: bool, }