Skip to content

Commit

Permalink
test: Remove add/remove death tests
Browse files Browse the repository at this point in the history
Seeing recent fialures on Windows
- rust-lang#13748
- rust-lang#13738
- rust-lang#13740

and maybe more

The test was added in rust-lang#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
  • Loading branch information
epage committed Apr 12, 2024
1 parent 7dc84a2 commit 7b30644
Showing 1 changed file with 0 additions and 149 deletions.
149 changes: 0 additions & 149 deletions tests/testsuite/death.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,155 +87,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) };
Expand Down

0 comments on commit 7b30644

Please sign in to comment.