From e12494bf082ef2c82353e4e88ba74c2c30d1addd Mon Sep 17 00:00:00 2001 From: michele Date: Mon, 27 Jun 2022 22:54:52 +0200 Subject: [PATCH] Close Async fixture + Timeout doesn't work #154 --- rstest/src/timeout.rs | 25 ++++++++++++- rstest/tests/resources/rstest/timeout.rs | 47 ++++++++++++++++++++++++ rstest/tests/rstest/mod.rs | 5 +++ 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/rstest/src/timeout.rs b/rstest/src/timeout.rs index 07edc3e..4f1d6c2 100644 --- a/rstest/src/timeout.rs +++ b/rstest/src/timeout.rs @@ -5,7 +5,7 @@ use futures::{select, Future, FutureExt}; #[cfg(feature = "async-timeout")] use futures_timer::Delay; -pub fn execute_with_timeout_sync T + Send + 'static>( +pub fn execute_with_timeout_sync T + Send + 'static>( code: F, timeout: Duration, ) -> T { @@ -17,7 +17,7 @@ pub fn execute_with_timeout_sync T + Send + 'stati } #[cfg(feature = "async-timeout")] -pub async fn execute_with_timeout_async, F: Fn() -> Fut>( +pub async fn execute_with_timeout_async, F: FnOnce() -> Fut>( code: F, timeout: Duration, ) -> T { @@ -69,6 +69,17 @@ mod tests { ) .await } + + #[async_std::test] + async fn should_compile_also_with_no_copy_move() { + struct S {} + async fn test(_s: S) { + assert!(true); + } + let s = S {}; + + execute_with_timeout_async(move || test(s), Duration::from_millis(20)).await + } } mod use_tokio_runtime { @@ -124,5 +135,15 @@ mod tests { Duration::from_millis(30), ) } + #[test] + fn should_compile_also_with_no_copy_move() { + struct S {} + fn test(_s: S) { + assert!(true); + } + let s = S {}; + + execute_with_timeout_sync(move || test(s), Duration::from_millis(20)) + } } } diff --git a/rstest/tests/resources/rstest/timeout.rs b/rstest/tests/resources/rstest/timeout.rs index ee71528..87b5a8c 100644 --- a/rstest/tests/resources/rstest/timeout.rs +++ b/rstest/tests/resources/rstest/timeout.rs @@ -81,6 +81,25 @@ mod thread { fn group_one_timeout_override(#[case] delay: Duration,#[case] expected: u32) { assert_eq!(expected, delayed_sum(2, 2, delay)); } + + struct S {} + + #[rstest] + #[case(S{})] + fn compile_with_no_copy_arg(#[case] _s: S) { + assert!(true); + } + + #[fixture] + fn no_copy() -> S { + S{} + } + + #[rstest] + fn compile_with_no_copy_fixture(no_copy: S) { + assert!(true); + } + } mod async_std_cases { @@ -159,4 +178,32 @@ mod async_std_cases { async fn group_one_timeout_override(#[case] delay: Duration, #[case] expected: u32) { assert_eq!(expected, delayed_sum(2, 2, delay).await); } + + struct S {} + + #[rstest] + #[case(S{})] + async fn compile_with_no_copy_arg(#[case] _s: S) { + assert!(true); + } + + #[fixture] + fn no_copy() -> S{ + S{} + } + + #[rstest] + fn compile_with_no_copy_fixture(_no_copy: S) { + assert!(true); + } + + #[fixture] + async fn a_fix() -> S{ + S{} + } + + #[rstest] + fn compile_with_async_fixture(#[future] a_fix: S) { + assert!(true); + } } \ No newline at end of file diff --git a/rstest/tests/rstest/mod.rs b/rstest/tests/rstest/mod.rs index 7284595..7809d57 100644 --- a/rstest/tests/rstest/mod.rs +++ b/rstest/tests/rstest/mod.rs @@ -917,6 +917,8 @@ fn timeout() { .ok("thread::group_one_timeout_override::case_1_pass") .fail("thread::group_one_timeout_override::case_2_fail_timeout") .fail("thread::group_one_timeout_override::case_3_fail_value") + .ok("thread::compile_with_no_copy_arg::case_1") + .ok("thread::compile_with_no_copy_fixture") .ok("async_std_cases::single_pass") .fail("async_std_cases::single_fail_value") .fail("async_std_cases::single_fail_timeout") @@ -932,6 +934,9 @@ fn timeout() { .ok("async_std_cases::group_one_timeout_override::case_1_pass") .fail("async_std_cases::group_one_timeout_override::case_2_fail_timeout") .fail("async_std_cases::group_one_timeout_override::case_3_fail_value") + .ok("async_std_cases::compile_with_no_copy_arg::case_1") + .ok("async_std_cases::compile_with_no_copy_fixture") + .ok("async_std_cases::compile_with_async_fixture") .assert(output); }