Skip to content

Commit

Permalink
[tests] Improve server test stability #903 (#904)
Browse files Browse the repository at this point in the history
improve shutdown
  • Loading branch information
michaelvlach authored Dec 21, 2023
1 parent 971855e commit 5f02b8b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions agdb_server/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const DEFAULT_PORT: u16 = 3000;
const ADMIN: &str = "admin";
const RETRY_TIMEOUT: Duration = Duration::from_secs(1);
const RETRY_ATTEMPS: u16 = 3;
const SHUTDOWN_RETRY_TIMEOUT: Duration = Duration::from_millis(100);
const SHUTDOWN_RETRY_ATTEMPTS: u16 = 30;

static MUTEX: OnceLock<Mutex<bool>> = OnceLock::new();
static SERVER: OnceLock<TestServerImpl> = OnceLock::new();
Expand Down Expand Up @@ -422,19 +424,23 @@ impl TestServerImpl {

impl Drop for TestServerImpl {
fn drop(&mut self) {
let shutdown_result = if self.process.try_wait().unwrap().is_none() {
Self::shutdown_server(self)
} else {
anyhow::Ok(())
};
if self.process.try_wait().unwrap().is_none() {
let _ = Self::shutdown_server(self);
}

for _ in 0..SHUTDOWN_RETRY_ATTEMPTS {
if self.process.try_wait().unwrap().is_some() {
break;
}
std::thread::sleep(SHUTDOWN_RETRY_TIMEOUT);
}

if shutdown_result.is_err() {
if self.process.try_wait().unwrap().is_none() {
let _ = self.process.kill();
}

let _ = self.process.wait();

shutdown_result.unwrap();
Self::remove_dir_if_exists(&self.dir).unwrap();
}
}

0 comments on commit 5f02b8b

Please sign in to comment.