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 miri support to tests suite #6900

Closed

Conversation

nurmohammed840
Copy link
Contributor

Many parts of the codebase can be tested with Miri.

However, Miri is not currently compatible with #[tokio::test] , At the moment Miri doesn't support some of the operations used by the runtime.

Solution

To address this, A new configuration miri was added to a custom tokio_test macro. to use this:

mod tokio {
    pub use tokio::*;
    pub use tokio_test_macros::tokio_test as test;
}

When the miri config is not present, it simply adds #[cfg_attr(miri, ignore)] to the test:

#[tokio::test]
async fn test_example() {}
#[test]
#[cfg_attr(miri, ignore)]
fn test_example() { ... }

However, when miri config is present, it generates the following code:

#[tokio::test(miri)]
async fn test_example() {}
#[test]
fn test_example() {
    let body = async {};
    if cfg!(miri) {
        // Use any simple thread based executor. For example:
        return future::executor::block_on(body);
    }
    // Otherwise, use the Tokio runtime
    // ...
}

This change DOES NOT affect the existing codebase in any way.

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

Successfully merging this pull request may close these issues.

1 participant