client_changing_workspace_lib_retains_diagnostics fails frequently on slow drives #1466
Description
The client_changing_workspace_lib_retains_diagnostics
test has been failing occasionally on CI:
- update miri rust#58706 (comment)
- Update cargo, rls, books rust#58920 (comment)
- Rollup of 7 pull requests rust#60472 (comment)
- [beta] save-analysis: Pull associated type definition using
qpath_def
rust#60881 (comment) - [beta] Prepare beta 1.36.0 rust#60999 (comment)
- [stable] Backport fix for #60989 "ICE with incorrect turbofish" rust#61085 (comment)
- [beta] Rollup backports rust#61283 (comment)
(possibly others, these are the ones that I can easily find)
I am able to reliably reproduce this error when using a magnetic spinning hard drive (around 80-90% failure rate) on both macos and windows.
After looking at the test, I'm fairly certain the reason is because the tests are sharing the cargo target directory. If one test (such as client_changing_workspace_lib_retains_diagnostics
) builds something called "liblibrary", and another test (say client_test_complete_self_crate_name
) creates a "liblibrary" at the same time, they will conflict with one another and stomp on each other's files.
I think the solution is that each test should use a dedicated target directory (that is how cargo's test suite works). I'm actually not sure how rls sets the target directory, or why the test suite is set up to reuse it, otherwise I would submit a PR. The following quick-and-dirty hack fixes the problem:
diff --git a/tests/support/client/mod.rs b/tests/support/client/mod.rs
index c563c98..0dcf1d0 100644
--- a/tests/support/client/mod.rs
+++ b/tests/support/client/mod.rs
@@ -58,6 +58,7 @@ impl Project {
pub fn rls_cmd(&self) -> Command {
let mut cmd = Command::new(rls_exe());
cmd.current_dir(self.root());
+ cmd.env("CARGO_TARGET_DIR", self.root().join("target").to_string_lossy().into_owned());
cmd.stderr(Stdio::inherit());
cmd