diff --git a/test-utils/src/dev/db.rs b/test-utils/src/dev/db.rs index 88361210bfa..47291062a31 100644 --- a/test-utils/src/dev/db.rs +++ b/test-utils/src/dev/db.rs @@ -527,14 +527,17 @@ impl CockroachInstance { */ pub async fn cleanup(&mut self) -> Result<(), anyhow::Error> { /* - * Kill the process and wait for it to exit so that we can remove the + * SIGTERM the process and wait for it to exit so that we can remove the * temporary directory that we may have used to store its data. We * don't care what the result of the process was. */ if let Some(child_process) = self.child_process.as_mut() { - child_process - .start_kill() - .context("sending SIGKILL to child process")?; + let pid = child_process.id().expect("Missing child PID") as i32; + let success = + 0 == unsafe { libc::kill(pid as libc::pid_t, libc::SIGTERM) }; + if !success { + anyhow!("Failed to send SIGTERM to DB"); + } child_process.wait().await.context("waiting for child process")?; self.child_process = None; } diff --git a/test-utils/src/dev/mod.rs b/test-utils/src/dev/mod.rs index 7749ed1ce70..efb9b7df437 100644 --- a/test-utils/src/dev/mod.rs +++ b/test-utils/src/dev/mod.rs @@ -102,6 +102,18 @@ pub async fn test_setup_database_seed(log: &Logger) { std::fs::create_dir_all(&dir).unwrap(); let mut db = setup_database(log, Some(&dir), StorageSource::Populate).await; db.cleanup().await.unwrap(); + + // See https://github.com/cockroachdb/cockroach/issues/74231 for context on + // this. We use this assertion to check that our seed directory won't point + // back to itself, even if it is copied elsewhere. + assert_eq!( + 0, + dir.join("temp-dirs-record.txt") + .metadata() + .expect("Cannot access metadata") + .len(), + "Temporary directory record should be empty after graceful shutdown", + ); } /// Set up a [`db::CockroachInstance`] for running tests. @@ -131,11 +143,12 @@ async fn setup_database( // If we're going to copy the storage directory from the seed, // it is critical we do so before starting the DB. if matches!(storage_source, StorageSource::CopyFromSeed) { + let seed = seed_dir(); info!(&log, "cockroach: copying from seed directory ({}) to storage directory ({})", - seed_dir().to_string_lossy(), starter.store_dir().to_string_lossy(), + seed.to_string_lossy(), starter.store_dir().to_string_lossy(), ); - copy_dir(seed_dir(), starter.store_dir()) + copy_dir(seed, starter.store_dir()) .expect("Cannot copy storage from seed directory"); }