Skip to content
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
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

add kill test #2996

wants to merge 11 commits into from

Conversation

YamasouA
Copy link

@YamasouA YamasouA commented Nov 17, 2024

part of #361
I implement kill test case in runtime-tools to youki.

@YamasouA YamasouA changed the title [WIP] add kill test add kill test Nov 17, 2024
@YJDoc2
Copy link
Collaborator

YJDoc2 commented Nov 18, 2024

@YamasouA please sign your commits. The instructions can be found at https://github.com/youki-dev/youki/pull/2996/checks?check_run_id=33094881373

@YamasouA
Copy link
Author

@YJDoc2
Thank you for your review!
I pass DCO.

Comment on lines 104 to 122
let kill_test = ConditionalTest::new(
"test_kill_container",
Box::new(|| true),
Box::new(run_kill_test_cases),
);
Copy link
Collaborator

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.

@YJDoc2
Copy link
Collaborator

YJDoc2 commented Nov 23, 2024

Hey @YamasouA , thanks for the PR. I have taken a basic look, and want to request a change -
The go tests usually put all test cases in a single function, but here we try to separate each test case as a different test, so it is easier to understand and maintain. see the code in #2976 , how it has created one test function for readonly=true and another for readonly=false.

Can I request you to change this code to split each test condition into its own testcase? So it will be one function for testing kill without id, one for kill non-existing container and so on.

@YamasouA YamasouA force-pushed the test/kill branch 2 times, most recently from 69d3901 to 8db2447 Compare December 7, 2024 08:55
YamasouA and others added 6 commits December 7, 2024 08:57
Signed-off-by: Akiyama <[email protected]>
Signed-off-by: Akiyama <[email protected]>
Signed-off-by: Yusuke Sakurai <[email protected]>
Signed-off-by: Akiyama <[email protected]>
Signed-off-by: Akiyama <[email protected]>
Signed-off-by: Akiyama <[email protected]>
Signed-off-by: Yusuke Sakurai <[email protected]>
Signed-off-by: Akiyama <[email protected]>
@YamasouA
Copy link
Author

YamasouA commented Dec 7, 2024

@YJDoc2
I fix your comment!
please review again!!

Copy link
Collaborator

@YJDoc2 YJDoc2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks ok, two things I'd request you to fix, Then I'll do the final review.

Comment on lines 13 to 14
TestResult::Passed => TestResult::Failed(anyhow!("Expected failure but got success")),
_ => TestResult::Failed(anyhow!("Unexpected test result")),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TestResult::Passed => TestResult::Failed(anyhow!("Expected failure but got success")),
_ => TestResult::Failed(anyhow!("Unexpected test result")),
TestResult::Passed => TestResult::Failed(anyhow!("Expected killing container with empty id to fail, but was successful")),
_ => TestResult::Failed(anyhow!("Unexpected test result")),

Similarly update the failed messages in others as well.

Comment on lines 37 to 47
match container.create() {
TestResult::Passed => {}
_ => return TestResult::Failed(anyhow!("Failed to create container")),
}
let result = match container.kill() {
TestResult::Passed => TestResult::Passed,
TestResult::Failed(_) => {
TestResult::Failed(anyhow!("Expected success but got failure"))
}
_ => TestResult::Failed(anyhow!("Unexpected test result")),
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in both these cases you can use test_result! macro to directly return the error without having to do manual match. Same for the cases below.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

container.kill() return TestResult. type.
So I think we don't have to use test_result macro.
Is it true?

@YamasouA
Copy link
Author

YamasouA commented Dec 9, 2024

@YJDoc2
Thank you for your review.
I fix your comment and fix lint error.

Copy link
Collaborator

@YJDoc2 YJDoc2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, so few things need change -

  1. I have left a couple of comments, please take a look.
  2. In the original go tests, it uses special config for stopped container and running container :
    • It uses a config with command true which would immediately exit, and thus we get a stopped container
    • It uses a config with command sleep 30 and waits 10 seconds so to make sure container is running and then attempts to kill the container for running container
      In our current lifecycle impl, we do not have support for passing custom command, we always use sleep 10. So to get the correct behavior we can either modify the lifecycle impl (maybe with a new fn) to allow customizing the command, or for stopped container test, we sleep 15 seconds, then kill and for running test we sleep ~3 seconds and then kill.

Can you check what would be better and update the test accordingly? Thanks :)

Comment on lines 58 to 65
match container.create() {
TestResult::Passed => {}
_ => return TestResult::Failed(anyhow!("Failed to create container")),
}
match container.delete() {
TestResult::Passed => {}
_ => return TestResult::Failed(anyhow!("Failed to delete container")),
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here you need to call container.start instead of delete, then wait a little, then call kill and finally delete.

Comment on lines 73 to 80
fn kill_start_container_test() -> TestResult {
let container = ContainerLifecycle::new();

// kill start container
match container.create() {
TestResult::Passed => {}
_ => return TestResult::Failed(anyhow!("Failed to recreate container")),
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be the last test case from original go test kill a running container ?

@YamasouA
Copy link
Author

@YJDoc2
I wrote some util function to support this test like your advice, and update test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants