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

Don't start the reactor when running Miri #3360

Closed
Kestrer opened this issue Dec 29, 2020 · 12 comments
Closed

Don't start the reactor when running Miri #3360

Kestrer opened this issue Dec 29, 2020 · 12 comments
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-runtime Module: tokio/runtime

Comments

@Kestrer
Copy link
Contributor

Kestrer commented Dec 29, 2020

It can be useful to run async tests in Miri. However, #[tokio::test] will currently attempt to start the reactor, which will cause an error in Miri as it isn't supported. By only starting the reactor on #[cfg(not(miri))], we will be able to run tests using Miri without having to use futures_executor::block_on or something like that.

@Kestrer Kestrer added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Dec 29, 2020
@Darksonn Darksonn added the M-runtime Module: tokio/runtime label Dec 29, 2020
@Darksonn
Copy link
Contributor

I suppose something like that could work.

@blasrodri
Copy link
Contributor

@Koxiaet
You’re thinking of ignoring this line when running Miri?

@Kestrer
Copy link
Contributor Author

Kestrer commented Jan 7, 2021

@blasrodri Even better, enable_io (and enable_time if Miri doesn't support it) could become a no-op on Miri, which also makes sense and is perhaps simpler

@RalfJung
Copy link

RalfJung commented Jan 8, 2021

FWIW, this should be done with care. cfg(miri) is mainly intended for test cases; we also use it in the standard library in a few places. There are situations in user code where this makes sense, and this might be one of them -- it is just important to be aware of the implication: the cfg'd-out code is not tested by Miri. So any such cfg introduces some risk that when testing things in Miri, one is not testing the things one thinks one is testing.

So when a library does this, it might be worth pointing this out somewhere in the documentation, at least.

@Darksonn
Copy link
Contributor

Darksonn commented Jan 8, 2021

It's possible that it is better to update tests to not enable IO so we don't run into the miri error on starting epoll. Then we can do it selectively on tests that don't depend on epoll, but are still e.g. threaded.

@blasrodri
Copy link
Contributor

blasrodri commented Jan 9, 2021

It's possible that it is better to update tests to not enable IO

Do you mean by modifying the proc macro, and changing the enable_all call in case is_test is true on function parse_knobs?

@Darksonn
Copy link
Contributor

Darksonn commented Jan 9, 2021

No, I meant modifying each test directly rather than modifying the macro. Tests which actually use IO should not be modified of course, as they simply cannot run with miri.

blasrodri added a commit to blasrodri/tokio that referenced this issue Jan 9, 2021
@carllerche
Copy link
Member

Until Miri is stabilized as part of the rust stable channel, I am inclined to not factor it in. The runtime builder provides sufficient configuration options to disable the IO driver.

@tiif
Copy link
Contributor

tiif commented Oct 12, 2024

A quick search on miri in the issue tracker led me to this issue, currently the #[tokio::test] issue appeared to be solved.

@nurmohammed840
Copy link
Contributor

@tiif, Just today I added this PR #6900, Without knowing that #[tokio::test] works on Linux, So I closed it.
Unfortunately, at the moment, it does not work on Windows.

@tiif
Copy link
Contributor

tiif commented Oct 12, 2024

Oh yea, you are right. I forgot that #[tokio::test] probably still won't work in MacOS or Windows. This is tracked under rust-lang/miri#1719.

@RalfJung
Copy link

RalfJung commented Oct 12, 2024

The recommendation for non-Linux users that need file system access or epoll support is to run Miri with --target x86_64-unknown-linux-gnu. That should work everywhere and does not require any special tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-runtime Module: tokio/runtime
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants