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

Runners use separate directories to allow parallelism #113

Closed
wants to merge 2 commits into from
Closed

Runners use separate directories to allow parallelism #113

wants to merge 2 commits into from

Conversation

Anders429
Copy link

This PR resolves the issues that are run into when running two separate unit tests in the same crate (see issue #58). Previously, doing this would cause the test runners to use the same crate directory, leading to one overwriting the other's manifest. This resulted in confusing errors and tests failing to no fault of the user.

To solve this, separate directories are defined for each run, using a hash of the test paths used by the TestCase. Therefore, the following now works correctly:

use trybuild::TestCases;

#[test]
fn test_1() {
    TestCases::new().compile_fail("compile_failures/1.rs");
}

#[test]
fn test_2() {
    TestCases::new().compile_fail("compile_failures/2.rs");
}

This does add a dependency on rustc-hash, the hasher used within rustc. I would say this is a trustworthy additional dependency, as it is owned by the Rust core team. The hash is not cryptographic, but it doesn't need to be for this use case. If you would rather not add this dependency, let me know and we can discuss another way.

@Anders429 Anders429 changed the title Runners use separate directories to allow parallelism6 Runners use separate directories to allow parallelism Apr 9, 2021
@Anders429
Copy link
Author

Ah, looks like rustc-hash would cause a bump in MSRV. After looking into it a little more, it looks like we can just use the DefaultHasher from the standard library, and it will accomplish the same thing without the extra dependency. I think that's the best way to go, since I don't want to unnecessarily cause bumps in the MSRV :)

Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer not to do this. In this approach the compilation of dependencies is not able to be shared between different trybuild invocations, and all the test outputs would still get interleaved/unreadable.

I would accept a PR to serialize the concurrent tests to run one after another using a file lock.

Thanks!

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.

2 participants