Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions test-utils/src/dev/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 15 additions & 2 deletions test-utils/src/dev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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");
}

Expand Down