Skip to content

Commit

Permalink
Close Async fixture + Timeout doesn't work #154
Browse files Browse the repository at this point in the history
  • Loading branch information
la10736 committed Jun 27, 2022
1 parent 45d9405 commit e12494b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
25 changes: 23 additions & 2 deletions rstest/src/timeout.rs
Expand Up @@ -5,7 +5,7 @@ use futures::{select, Future, FutureExt};
#[cfg(feature = "async-timeout")]
use futures_timer::Delay;

pub fn execute_with_timeout_sync<T: 'static + Send, F: Fn() -> T + Send + 'static>(
pub fn execute_with_timeout_sync<T: 'static + Send, F: FnOnce() -> T + Send + 'static>(
code: F,
timeout: Duration,
) -> T {
Expand All @@ -17,7 +17,7 @@ pub fn execute_with_timeout_sync<T: 'static + Send, F: Fn() -> T + Send + 'stati
}

#[cfg(feature = "async-timeout")]
pub async fn execute_with_timeout_async<T, Fut: Future<Output = T>, F: Fn() -> Fut>(
pub async fn execute_with_timeout_async<T, Fut: Future<Output = T>, F: FnOnce() -> Fut>(
code: F,
timeout: Duration,
) -> T {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
}
}
47 changes: 47 additions & 0 deletions rstest/tests/resources/rstest/timeout.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
5 changes: 5 additions & 0 deletions rstest/tests/rstest/mod.rs
Expand Up @@ -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")
Expand All @@ -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);
}

Expand Down

0 comments on commit e12494b

Please sign in to comment.