From 6122d5be20383c0a6a50327258ea9da8e2d72df5 Mon Sep 17 00:00:00 2001 From: "Alex Chi Z." <4198311+skyzh@users.noreply.github.com> Date: Sat, 2 Nov 2024 01:27:57 -0400 Subject: [PATCH] feat: support serial run (#6) Signed-off-by: Alex Chi --- src/apply.rs | 27 +++++++++++++++++++++++++-- src/lib.rs | 2 +- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/apply.rs b/src/apply.rs index 9d83900..a3267f3 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, Clone)] +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;