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

Fix dogfood tests #3444

Merged
merged 5 commits into from
Dec 6, 2018
Merged

Fix dogfood tests #3444

merged 5 commits into from
Dec 6, 2018

Conversation

waynr
Copy link
Contributor

@waynr waynr commented Nov 21, 2018

@mati865 @flip1995 following up on the discussion in #3443.

I'm currently having trouble getting the dogfood test to fail consistently when there is a known lint failure in the clippy_lints subdirectory. The problem seems to be that if the dogfood test case is run before the dogfood_tests test case, the former will always pass whereas it fails correctly if it is second.

@flip1995
Copy link
Member

flip1995 commented Nov 21, 2018

You can add a test function that calls the two test functions in the right order:

#[test]
fn dogfood_runner() {
    dogfood_tests();
    dogfood();
}

and remove the #[test] attribute from the other two functions.

tests/dogfood.rs Outdated
let root_dir = std::env::current_dir().unwrap();
for d in &[".", "clippy_lints", "rustc_tools_util", "clippy_dev"] {
let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let clippy_cmd = std::path::Path::new(&root_dir).join("target/debug/cargo-clippy");
Copy link

@ghost ghost Nov 21, 2018

Choose a reason for hiding this comment

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

cargo run ensured that the executable was built. I'm not sure if this is a problem but won't this break if the tests are run in release mode without building in debug first i.e. cargo clean; cargo test --release;. Also will the / path separators work on Windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point, is there a good way to handle release vs debug mode in the binary itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could be wrong, but I think std::path::Path will normalize path separators appropriately for the current operating system. Check this out in the docs: https://doc.rust-lang.org/1.26.0/std/path/struct.Path.html#examples which has a comment indicating that Path::new("./foo/bar.txt") will work on Windows; if that works then I imagine other methods that operate on Path would also.

Copy link
Member

Choose a reason for hiding this comment

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

There is cfg!(debug_assertions).

@waynr
Copy link
Contributor Author

waynr commented Nov 25, 2018

@mikerite @flip1995 I think this is ready for another review pass

@phansch phansch added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Nov 27, 2018
@waynr waynr force-pushed the fix-dogfood-tests branch from 312c0d0 to 92beef7 Compare November 28, 2018 19:48
@waynr
Copy link
Contributor Author

waynr commented Nov 28, 2018

Fixed the merge conflicts.

tests/dogfood.rs Outdated
@@ -8,22 +8,65 @@
// except according to those terms.

#[test]
fn dogfood_runner() {
dogfood();
dogfood_tests();
Copy link
Member

Choose a reason for hiding this comment

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

Is this really the right order? Shouldn't it be the other way around or did I misunderstood your comment on this?

Copy link
Contributor Author

@waynr waynr Nov 29, 2018

Choose a reason for hiding this comment

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

It looks like I was mistaken that the order in which the tests are run makes a difference. I've been using the following shell snippet to validate that this dogfood_runner function fixes the indeterminism (regardless of the actual order the implementation functions are called):

for i in $(seq 1 10 ) ;do
echo "run $i"
cargo test --test dogfood
done

Whenever I use the the dogfood_runner function the dogfood case consistently fails when it should, but if I move the #[test] decoration from dogfood_runner to each of dogfood and dogfood_tests the dogfood case only fails when it should something roughly every 3 out of 10 runs, sometimes it just always passes. It's kind of baffling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, coming back to this after reading through the cargo docs I think the indeterminism stems not from an ordering issue, but from a parallelism issue:

When you run multiple tests, by default they run in parallel using threads. This means the tests will finish running faster so you can get feedback quicker on whether or not your code is working. Because the tests are running at the same time, make sure your tests don’t depend on each other or on any shared state, including a shared environment, such as the current working directory or environment variables.

Both test cases do set the current working directory on the test process itself, but should instead be setting the current working directory only on the child process they are executing. I'm about to push a change to fix this.

@flip1995
Copy link
Member

flip1995 commented Dec 5, 2018

Sorry I didn't get back to this for that long.

This LGTM now. But since it changes pretty much of our CI setup I would like to have a second opinion on this. cc @mikerite @phansch

(Also needs a rebase)

@phansch
Copy link
Member

phansch commented Dec 5, 2018

LGTM, too.

@waynr waynr force-pushed the fix-dogfood-tests branch from f6b5101 to 0442bb9 Compare December 6, 2018 00:18
@waynr
Copy link
Contributor Author

waynr commented Dec 6, 2018

Okay, this has been rebased onto master branch @flip1995 @phansch

@phansch phansch merged commit 7cb1b1f into rust-lang:master Dec 6, 2018
@phansch
Copy link
Member

phansch commented Dec 6, 2018

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants