-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add kill test #2996
Open
YamasouA
wants to merge
11
commits into
youki-dev:main
Choose a base branch
from
YamasouA:test/kill
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add kill test #2996
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cbbbf7b
add kill test
YamasouA 00d3c5e
lint
YamasouA 72ad34d
add test process_oom_score_adj
saku3 6d9ecd5
split test func
YamasouA 01761ff
fix test
YamasouA c2ed117
add test process_oom_score_adj
saku3 c736a23
fix format, error message, use test_result!
YamasouA 9035e80
don't use test_result macro
YamasouA 71e82b2
add util func for kill_test
YamasouA c623e21
can compile and use formatter
YamasouA 5dc2dbf
use waiting_for_status
YamasouA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
add kill test
Signed-off-by: Akiyama <[email protected]>
- Loading branch information
commit cbbbf7b36b94fe5a1349cee59ced936c8ad9146d
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
use test_framework::{ConditionalTest, TestGroup, TestResult}; | ||
use crate::tests::lifecycle::ContainerLifecycle; | ||
use anyhow::anyhow; | ||
|
||
fn run_kill_test_cases() -> TestResult { | ||
let mut container = ContainerLifecycle::new(); | ||
let mut results = vec![]; | ||
let container_id = container.get_id().to_string(); | ||
|
||
// kill with empty id | ||
container.set_id(""); | ||
results.push(( | ||
"kill without ID", | ||
match container.kill() { | ||
TestResult::Failed(_) => TestResult::Passed, | ||
TestResult::Passed => TestResult::Failed(anyhow!("Expected failure but got success")), | ||
_ => TestResult::Failed(anyhow!("Unexpected test result")), | ||
}, | ||
)); | ||
|
||
// kill for non existed container | ||
container.set_id("non-existent-container-id"); | ||
results.push(( | ||
"kill non-existent container", | ||
match container.kill() { | ||
TestResult::Failed(_) => TestResult::Passed, | ||
TestResult::Passed => TestResult::Failed(anyhow!("Expected failure but got success")), | ||
_ => TestResult::Failed(anyhow!("Unexpected test result")), | ||
}, | ||
)); | ||
|
||
// kill created container | ||
container.set_id(&container_id); | ||
match container.create() { | ||
TestResult::Passed => {} | ||
_ => return TestResult::Failed(anyhow!("Failed to create container")), | ||
} | ||
results.push(( | ||
"kill created container", | ||
match container.kill() { | ||
TestResult::Passed => TestResult::Passed, | ||
TestResult::Failed(_) => TestResult::Failed(anyhow!("Expected success but got failure")), | ||
_ => TestResult::Failed(anyhow!("Unexpected test result")), | ||
}, | ||
)); | ||
|
||
// kill stopped container | ||
match container.delete() { | ||
TestResult::Passed => {} | ||
_ => return TestResult::Failed(anyhow!("Failed to delete container")), | ||
} | ||
results.push(( | ||
"kill stopped container", | ||
match container.kill() { | ||
TestResult::Failed(_) => TestResult::Passed, | ||
TestResult::Passed => TestResult::Failed(anyhow!("Expected failure but got success")), | ||
_ => TestResult::Failed(anyhow!("Unexpected test result")), | ||
}, | ||
)); | ||
|
||
// kill start container | ||
match container.create() { | ||
TestResult::Passed => {} | ||
_ => return TestResult::Failed(anyhow!("Failed to recreate container")), | ||
} | ||
|
||
match container.start() { | ||
TestResult::Passed => {} | ||
TestResult::Failed(err) => { | ||
return TestResult::Failed(anyhow!("Failed to start container: {:?}", err)); | ||
} | ||
_ => unreachable!(), | ||
} | ||
results.push(( | ||
"kill running container", | ||
match container.kill() { | ||
TestResult::Passed => TestResult::Passed, | ||
TestResult::Failed(_) => TestResult::Failed(anyhow!("Expected success but got failure")), | ||
_ => TestResult::Failed(anyhow!("Unexpected test result")), | ||
}, | ||
)); | ||
|
||
match container.delete() { | ||
TestResult::Passed => {} | ||
_ => return TestResult::Failed(anyhow!("Failed to delete container")), | ||
} | ||
|
||
for (name, result) in results { | ||
if let TestResult::Failed(err) = result { | ||
return TestResult::Failed(anyhow!("Test '{}' failed: {:?}", name, err)); | ||
} | ||
} | ||
|
||
TestResult::Passed | ||
} | ||
|
||
pub fn get_kill_test() -> TestGroup { | ||
let mut test_group = TestGroup::new("kill_container"); | ||
let kill_test = ConditionalTest::new( | ||
"test_kill_container", | ||
Box::new(|| true), | ||
Box::new(run_kill_test_cases), | ||
); | ||
test_group.add(vec![Box::new(kill_test)]); | ||
test_group | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod kill_test; | ||
|
||
pub use kill_test::get_kill_test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ pub mod seccomp; | |
pub mod seccomp_notify; | ||
pub mod sysctl; | ||
pub mod tlb; | ||
pub mod kill; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use normal test instead of ConditionalTest here, that will not require a conditional function.