From 30efa8d9c543984e06be18810893f457c74b83f4 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 12 Apr 2024 16:06:15 -0500 Subject: [PATCH] test: Remove add/remove death tests Seeing recent fialures on Windows - #13748 - #13738 - #13740 and maybe more The test was added in #12744. It seems of limited utility because there are innumerable ways of adding new writes that aren't atomic and we can't test for them all. Even this case, its limited. See also https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Flaky.20test.3A.20.20-death.3A.3Akill_cargo_add_never_corrupts_cargo/near/432979594 --- tests/testsuite/death.rs | 150 --------------------------------------- 1 file changed, 150 deletions(-) diff --git a/tests/testsuite/death.rs b/tests/testsuite/death.rs index b61896dc917..f9049a8f168 100644 --- a/tests/testsuite/death.rs +++ b/tests/testsuite/death.rs @@ -6,7 +6,6 @@ use std::io::{self, Read}; use std::net::TcpListener; use std::process::{Child, Stdio}; use std::thread; -use std::time; #[cargo_test] fn ctrl_c_kills_everyone() { @@ -87,155 +86,6 @@ fn ctrl_c_kills_everyone() { ); } -#[cargo_test] -fn kill_cargo_add_never_corrupts_cargo_toml() { - cargo_test_support::registry::init(); - cargo_test_support::registry::Package::new("my-package", "0.1.1+my-package").publish(); - - let with_dependency = r#" -[package] -name = "foo" -version = "0.0.1" -authors = [] - -[dependencies] -my-package = "0.1.1" -"#; - let without_dependency = r#" -[package] -name = "foo" -version = "0.0.1" -authors = [] -"#; - - for sleep_time_ms in [30, 60, 90] { - let p = project() - .file("Cargo.toml", without_dependency) - .file("src/lib.rs", "") - .build(); - - let mut cargo = p.cargo("add").arg("my-package").build_command(); - cargo - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()); - - let mut child = cargo.spawn().unwrap(); - - thread::sleep(time::Duration::from_millis(sleep_time_ms)); - - assert!(child.kill().is_ok()); - assert!(child.wait().is_ok()); - - // check the Cargo.toml - let contents = fs::read(p.root().join("Cargo.toml")).unwrap(); - - // not empty - assert_ne!( - contents, b"", - "Cargo.toml is empty, and should not be at {} milliseconds", - sleep_time_ms - ); - - // We should have the original Cargo.toml or the new one, nothing else. - if std::str::from_utf8(&contents) - .unwrap() - .contains("[dependencies]") - { - assert_eq!( - std::str::from_utf8(&contents).unwrap(), - with_dependency, - "Cargo.toml is with_dependency after add at {} milliseconds", - sleep_time_ms - ); - } else { - assert_eq!( - std::str::from_utf8(&contents).unwrap(), - without_dependency, - "Cargo.toml is without_dependency after add at {} milliseconds", - sleep_time_ms - ); - } - } -} - -#[cargo_test] -fn kill_cargo_remove_never_corrupts_cargo_toml() { - let with_dependency = r#" -[package] -name = "foo" -version = "0.0.1" -authors = [] -build = "build.rs" - -[dependencies] -bar = "0.0.1" -"#; - let without_dependency = r#" -[package] -name = "foo" -version = "0.0.1" -authors = [] -build = "build.rs" -"#; - - // This test depends on killing the cargo process at the right time to cause a failed write. - // Note that we're iterating and using the index as time in ms to sleep before killing the cargo process. - // If it is working correctly, we never fail, but can't hang out here all day... - // So we'll just run it a few times and hope for the best. - for sleep_time_ms in [30, 60, 90] { - // new basic project with a single dependency - let p = project() - .file("Cargo.toml", with_dependency) - .file("src/lib.rs", "") - .build(); - - // run cargo remove the dependency - let mut cargo = p.cargo("remove").arg("bar").build_command(); - cargo - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()); - - let mut child = cargo.spawn().unwrap(); - - thread::sleep(time::Duration::from_millis(sleep_time_ms)); - - assert!(child.kill().is_ok()); - assert!(child.wait().is_ok()); - - // check the Cargo.toml - let contents = fs::read(p.root().join("Cargo.toml")).unwrap(); - - // not empty - assert_ne!( - contents, b"", - "Cargo.toml is empty, and should not be at {} milliseconds", - sleep_time_ms - ); - - // We should have the original Cargo.toml or the new one, nothing else. - if std::str::from_utf8(&contents) - .unwrap() - .contains("[dependencies]") - { - assert_eq!( - std::str::from_utf8(&contents).unwrap(), - with_dependency, - "Cargo.toml is not the same as the original at {} milliseconds", - sleep_time_ms - ); - } else { - assert_eq!( - std::str::from_utf8(&contents).unwrap(), - without_dependency, - "Cargo.toml is not the same as expected at {} milliseconds", - sleep_time_ms - ); - } - } -} - #[cfg(unix)] pub fn ctrl_c(child: &mut Child) { let r = unsafe { libc::kill(-(child.id() as i32), libc::SIGINT) };