Skip to content

Commit

Permalink
add timeout after kill for test setup (#52)
Browse files Browse the repository at this point in the history
* add timeout after kill

* Auto Format Changes

* clippy

---------

Co-authored-by: Format Bot <>
  • Loading branch information
hazel-sudz authored Dec 16, 2024
1 parent cdd4612 commit 29e4304
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ mod tests {
#[tokio::test]
#[serial]
async fn test_shard_attachment() {
crate::integration::test_setup::setup_test();
crate::integration::test_setup::setup_test().await;

let test_router_client = TestRouterClient::new();
let test_client = test_router_client.get_client();
Expand Down Expand Up @@ -416,5 +416,7 @@ mod tests {
client_shard_info_responses[0].read_shard_info.len(),
write_shards as usize
);

crate::integration::test_setup::test_teardown().await;
}
}
4 changes: 2 additions & 2 deletions src/integration/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod tests {
#[serial]
async fn test_basic_integration() -> Result<()> {
let r: Result<()> = {
test_setup::setup_test();
test_setup::setup_test().await;

// start everything
let mut info_cmd = Command::cargo_bin("info")?;
Expand Down Expand Up @@ -61,7 +61,7 @@ mod tests {
Ok(())
};

test_setup::test_teardown();
test_setup::test_teardown().await;
r
}

Expand Down
25 changes: 9 additions & 16 deletions src/integration/test_setup.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// kill any dangling info shard processes for test setup

#[cfg(test)]
pub fn setup_test() {
async fn kill_dangling() {
let system = sysinfo::System::new_all();

let ps = system.processes().iter().filter(|(_, p)| {
Expand All @@ -13,22 +14,14 @@ pub fn setup_test() {
for (_, process) in ps {
process.kill();
}
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
}

#[cfg(test)]
pub fn test_teardown() {
let system = sysinfo::System::new_all();

let ps = system.processes().iter().filter(|(_, p)| {
p.name().to_str().unwrap().eq("info")
|| p.name().to_str().unwrap().eq("read_shard")
|| p.name().to_str().unwrap().eq("write_shard")
|| p.name().to_str().unwrap().eq("client")
});
pub async fn setup_test() {
kill_dangling().await
}

for (_pid, process) in ps {
let name = process.name().to_str().unwrap();
println!("killing {name}");
process.kill();
}
#[cfg(test)]
pub async fn test_teardown() {
kill_dangling().await
}
4 changes: 3 additions & 1 deletion src/io/router_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ mod test {
#[tokio::test]
#[serial]
async fn test_example_router() -> Result<()> {
test_setup::setup_test();
test_setup::setup_test().await;

let debug_out1: Arc<RwLock<Vec<Vec<u8>>>> = Arc::new(RwLock::new(Vec::new()));
let debug_out2: Arc<RwLock<Vec<Vec<u8>>>> = Arc::new(RwLock::new(Vec::new()));
Expand Down Expand Up @@ -151,6 +151,8 @@ mod test {
*debug_out1,
vec![vec![1, 2, 3, 4], vec![1, 2, 3, 4], vec![1, 2, 3, 4]]
);

test_setup::test_teardown().await;
Ok(())
}
}

0 comments on commit 29e4304

Please sign in to comment.