-
Notifications
You must be signed in to change notification settings - Fork 349
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 integration tests for life cycle #113
Add integration tests for life cycle #113
Conversation
@minakawa-daiki |
I'd like to ask about binary generation for tests. Currently, the binary obtained by |
@minakawa-daiki |
I agree with @utam0k. It would be best to split this out into another module. I would be really interested in contributing in this area, as I think we'll want to start building out our own test suite for cgroups v2. Maybe we could even make this not a cargo test at all, and do something similar to the oci runtime-tools and use the test anything protocol or similar. This way we can essentially just run the built tests which can invoke a new build of the project and test it without having to do anything hacky with cargo. Food for thought. |
I apologize for the delay in my response. It's certainly better to separate it as a testing tool, and I've reminded myself that there's no need to force it to be included in |
@minakawa-daiki Let me know if you need any help with this. I think if the effort to break this out into it's own tool is too high that perhaps we allow this change in, and when I have time I can move this into it's own crate which will serve as a place to build out our own integration testing tool. What do you think @utam0k? |
@tsturzl |
Hey, I was checking the test anything protocol which is used by oci-spec validation tests, and rust has testanything crate which provides producer of data for tests as per TAP protocol. I'm not sure how much maintained and active it is, but that might be useful. We can use that as the part of our main program, and take path of youki executable and bundle etc.as cmd options. Then our binary will run all the tests that are in oci-validation tests, written in rust, and produce output using testanything. Maybe that way we won't need to create a complete tool for testing right now, instead just port validation suite, which will be used by us to validate the changes. @minakawa-daiki @tsturzl ? |
@YJDoc2 |
@utam0k @tsturzl @YJDoc2 |
rand = "0.8.0" | ||
tar = "0.4" | ||
flate2 = "1.0" | ||
testanything = "0.2.1" |
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.
How about error handling anyhow?
youki_integration_test/src/main.rs
Outdated
} | ||
|
||
// This tests the entire lifecycle of the container. | ||
fn life_cycle_test(project_path: &PathBuf) { |
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.
The same applies to the other functions, it is recommended to do the following
fn life_cycle_test(project_path: &PathBuf) { | |
fn life_cycle_test(project_path: &Path) { |
https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
|
||
pub fn initialize_test(project_path: &PathBuf) -> Result<(), std::io::Error> { | ||
let result = prepare_test_workspace(project_path); | ||
return result; |
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.
The return
is unnecessary.
|
||
pub fn cleanup_test(project_path: &PathBuf) -> Result<(), std::io::Error> { | ||
let result = delete_test_workspace(project_path); | ||
return result; |
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.
The return
is unnecessary.
|
||
pub fn create_project_path() -> PathBuf { | ||
let current_dir_path_result = env::current_dir(); | ||
return match current_dir_path_result { |
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.
The return
is unnecessary.
.finalize() | ||
} | ||
|
||
pub fn print_test_results(test_name: &str, tests: Vec<TapTest>) -> () { |
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.
The ()
is unnecessary.
// TODO Allow to receive arguments. | ||
// TODO Wrapping up the results | ||
pub fn exec(project_path: &PathBuf, id: &str) -> bool { | ||
let status = Command::new(project_path.join(PathBuf::from("youki"))) |
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.
I think "youki"
is too hard coding, so how about using an environment value, e.g. RUNTIME
I think the default value should be youki.
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.
What would be your thoughts on using cmd args instead of env vars? That way we user won't have to define env vars specifically for this purpose, and it might make more sense to pass those as args to the command, rather than to set them as general env vars.
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.
@utamoku What do you think about this?
My feeling is that when comparing env vars
and cmd args
, env vars
is basically unchanged and users are expected to use default values, while cmd args
is assumed to be specified by users.
In this case, I think env vars
is fine because it is basically used with youki
, but cmd args
may be an option if you are considering using a runtime other than youki
in the future.
youki_integration_test/src/main.rs
Outdated
|
||
// This tests the entire lifecycle of the container. | ||
fn life_cycle_test(project_path: &PathBuf) { | ||
let youki = Container::new(project_path); |
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.
I felt that the variable name container_runtime
was a better level of abstraction.
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.
Nice!
However, I commented on a few points.
But basically, I think that once the commented parts are fixed, we can merge them and discuss them with the developers to improve the whole` thing. It is good enough for a first prototype.
@minakawa-daiki I ran the test according to the README, and it failed. Is there something wrong with this?
|
Would it be possible , that instead of relying on panic as indication of test failure, we take the result of spawned process, along with its stderr, and accordingly set status and error message? That way we can have more information on why the test failed. |
As for the error messages, I'll change the implementation to use |
@utamoku Corrected the reviews we received except for the hard coding of the |
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.
This is a great PR move. And it is one of the most needed features in youki right now. However, I think there are still many things to be developed in this PR. Let's merge it once and improve it together.
Implemented integration tests.
First of all, I implemented tests for the container lifecycle and the
create
command, referring toopencontainers/runtime-tools
.See
tests/README.md
for how to run the integration tests.The flow of test execution is not to run
cargo test
directly, but to first generate a binary and then run it viasudo
.I am currently trying not to put it on the CI, but will do so if I can.
ref: #56