1
0
Fork 0
mirror of https://github.com/containers/youki synced 2024-06-08 15:56:16 +02:00

Move sleep after sending kill signal to test itself

Sleeping is necessary only when running all lifecycle tests,
as otherwise container is still running when we try to delete, and delete test fails.
But keeping sleep in kill function slows all other test where we do not try deleting immidiately afterwards.
Thus moved the sleep in the kill test itself, so only happend when testing lifecycle functions.
This commit is contained in:
Yashodhan Joshi 2021-09-19 21:01:02 +05:30
parent 3a0882db6e
commit afd546bc26
2 changed files with 12 additions and 11 deletions

View File

@ -1,8 +1,15 @@
use crate::utils::{generate_uuid, prepare_bundle, TempDir};
use std::thread::sleep;
use std::time::Duration;
use test_framework::{TestResult, TestableGroup};
use super::{create, delete, kill, start, state};
// By experimenting, somewhere around 50 is enough for youki process
// to get the kill signal and shut down
// here we add a little buffer time as well
const SLEEP_TIME: u64 = 75;
pub struct ContainerLifecycle {
project_path: TempDir,
container_id: String,
@ -37,7 +44,11 @@ impl ContainerLifecycle {
}
pub fn kill(&self) -> TestResult {
kill::kill(&self.project_path, &self.container_id)
let ret = kill::kill(&self.project_path, &self.container_id);
// sleep a little, so the youki process actually gets the signal and shuts down
// otherwise, the tester moves on to next tests before the youki has gotten signal, and delete test can fail
sleep(Duration::from_millis(SLEEP_TIME));
ret
}
pub fn delete(&self) -> TestResult {

View File

@ -2,15 +2,8 @@ use super::get_result_from_output;
use crate::utils::get_runtime_path;
use std::path::Path;
use std::process::{Command, Stdio};
use std::thread::sleep;
use std::time::Duration;
use test_framework::TestResult;
// By experimenting, somewhere around 50 is enough for youki process
// to get the kill signal and shut down
// here we add a little buffer time as well
const SLEEP_TIME: u64 = 75;
pub fn kill(project_path: &Path, id: &str) -> TestResult {
let res = Command::new(get_runtime_path())
.stdout(Stdio::piped())
@ -23,8 +16,5 @@ pub fn kill(project_path: &Path, id: &str) -> TestResult {
.spawn()
.expect("failed to execute kill command")
.wait_with_output();
// sleep a little, so the youki process actually gets the signal and shuts down
// otherwise, the tester moves on to next tests before the youki has gotten signal, and delete test can fail
sleep(Duration::from_millis(SLEEP_TIME));
get_result_from_output(res)
}