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

1.3.1 breaks tests that worked before #197

Open
threema-donat opened this issue Mar 4, 2024 · 6 comments
Open

1.3.1 breaks tests that worked before #197

threema-donat opened this issue Mar 4, 2024 · 6 comments

Comments

@threema-donat
Copy link

Hey there!

I recently updated the dependencies of a crate via cargo audit, which broke all the tests where we used tokio as runtime and mockito for mocking a http server because of starting a runtime from within a runtime.

I concluded that the version 1.3.1 of mockito should actually have been a breaking release.

@lipanski
Copy link
Owner

lipanski commented Mar 4, 2024

@threema-donat can you share some of the breaking tests or some minimal code to reproduce this? did you manage to fix the tests for 1.3.1 and if so, what did you have to do? could this be related to calling the sync methods from within an async runtime (which was never supported - see the async section inside the docs)?

@punkeel
Copy link

punkeel commented Mar 8, 2024

+1, our async tests broke after updating mockito v1.1.0 -> v1.4.0.

Cannot start a runtime from within a runtime. This happens because a function (like `block_on`) attempted to block the current thread while the thread is being used to drive asynchronous tasks.

I'm glad they broke, but may I nonetheless suggest detecting this (if at all possible) and printing a more useful error message (pointing to the docs)?

@lipanski
Copy link
Owner

lipanski commented Mar 8, 2024

@punkeel I assume the reason was using the sync methods instead of the async ones inside async tests, right?

This is one of the reasons I mention the error in the docs (though I think it's a slightly different version). I could add the other error message to the docs as well. Not sure if there's any other (easy) way to hint users about this.

This is I guess one of the downsides of supporting both a sync and an async interface but I don't intend to change that any time soon.

@punkeel
Copy link

punkeel commented Mar 8, 2024

Yep, exactly that

@punkeel
Copy link

punkeel commented Mar 9, 2024

It looks like it's possible (and easy) to tell if a function is called in the context of a Tokio runtime:

tokio::runtime::Handle::try_current()
    .expect_err("mockito error: use async methods when running inside Tokio - .... link to docs");

Would it make sense to detect this scenario and print a custom message guiding users to the docs?

@threema-donat
Copy link
Author

Sorry for the late reply; It was also due to this mistake that our tests broke. A custom message would certainly make the update to the latest version easier.

I would have expected the minor version to be increased if this worked before and not anymore in version '1.3.1'. Also, a note could have been added to the version to make the migration easier for people who mistakenly called the sync methods.

Thanks a lot for your work!

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

3 participants