Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support serial run #6

Merged
merged 2 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading