Skip to content

Commit

Permalink
feat: support serial run (#6)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Chi <[email protected]>
  • Loading branch information
skyzh authored Nov 2, 2024
1 parent 4a0a5f9 commit 6122d5b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
27 changes: 25 additions & 2 deletions src/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F, Ft, R>(path: impl AsRef<Path>, runner_fn: F) -> Result<()>
where
F: Fn() -> Ft + Send + Sync + 'static,
Ft: Future<Output = Result<R>> + Send,
R: PlannerTestRunner + 'static,
{
planner_test_apply_with_options(path, runner_fn, PlannerTestApplyOptions::default()).await
}

pub async fn planner_test_apply_with_options<F, Ft, R>(
path: impl AsRef<Path>,
runner_fn: F,
options: PlannerTestApplyOptions,
) -> Result<()>
where
F: Fn() -> Ft + Send + Sync + 'static,
Ft: Future<Output = Result<R>> + Send,
Expand Down Expand Up @@ -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![];
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6122d5b

Please sign in to comment.