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

Add timeouts #136

Closed
tbraun96 opened this issue Feb 13, 2022 · 8 comments
Closed

Add timeouts #136

tbraun96 opened this issue Feb 13, 2022 · 8 comments

Comments

@tbraun96
Copy link

The option to timing out the test should be a parameter. E.g.,:

#[timeout(Duration::from_millis(1000))]
fn test_apple() {

}

When async is detected, a timeout future can be wrapped around the test itself, terminating if it times out.

@la10736
Copy link
Owner

la10736 commented Feb 14, 2022

Ok... I guess you can use ntest crate and combine it with rstest but as far I can see ntest don't support async tests.

Anyway I can try to introduce this feature in rstest. I'm not an expert but I guess that aync timeout depend from which runtime do you use and this can be very tricky to handle.

@tpbraun96
Copy link

You can make timeouts runtime-agnostic: https://docs.rs/futures-timer/latest/futures_timer/index.html

@la10736
Copy link
Owner

la10736 commented Feb 19, 2022

Seams great!! Thanks

@la10736
Copy link
Owner

la10736 commented Mar 26, 2022

Ok, I wrote a proof of concept
https://gist.github.com/la10736/6a3652c12d065d0201e36b3fc97f1caf#file-test_timeout-rs

But before start I need to refactor the project to split procedural macro crate from utility functions.

la10736 added a commit that referenced this issue Apr 27, 2022
la10736 added a commit that referenced this issue May 1, 2022
@la10736
Copy link
Owner

la10736 commented May 1, 2022

TODO

  • documentation (Doc and README)
  • Open a new ticket for handling magic conversions from literals to Duration

la10736 added a commit that referenced this issue May 15, 2022
la10736 added a commit that referenced this issue May 15, 2022
@aviramha
Copy link
Contributor

@la10736 Timeout doesn't seem to work with async fixtures:

    #[rstest]
    #[timeout(std::time::Duration::from_secs(100))]
    #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
    async fn test_sanity_flow(#[future] service: EchoService) {
        let _ = service.await;
        assert_eq!(1, 1);
    }

error:

196 |     #[rstest]
    |     --------- captured by this `Fn` closure
...
199 |     async fn test_sanity_flow(#[future] service: EchoService) {
    |                                         ^^^^^^^
    |                                         |
    |                                         captured outer variable
    |                   

@la10736
Copy link
Owner

la10736 commented Jun 27, 2022

Ok... I missed it in my test :(

Can you open a new ticket for this bug/limit?

I've just forget to close this ticket before.

@la10736 la10736 closed this as completed Jun 27, 2022
@aviramha
Copy link
Contributor

Ok... I missed it in my test :(

Can you open a new ticket for this bug/limit?

I've just forget to close this ticket before.

Sure!
#154

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants