-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 network container tests #11583
Add network container tests #11583
Conversation
r? @epage (rustbot has picked a reviewer for you, use r? to override) |
remove_if_exists(&self.name); | ||
} | ||
} | ||
|
||
fn remove_if_exists(name: &str) { | ||
if let Err(e) = Command::new("docker") | ||
.args(&["container", "rm", "--force", name]) | ||
.output() | ||
{ | ||
panic!("failed to run docker: {e}"); | ||
} | ||
} |
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.
While this is test code, I thought panic during Drop
is problematic.
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.
Yea, it should generally always be avoided. In this particular case, I wasn't too concerned because the panic should be extremely unlikely. The only way for it to happen in the drop is if it fails to launch docker
, but that should only happen if it isn't in PATH (which can't happen because the handle won't be created otherwise), or if the system is running out of memory or file descriptors (in which case you've probably got bigger problems). I was more interested in sharing this function in the two places it is used and to keep the code simple. I can make it return a Result and move the panic to the other location if you think it would make that clearer?
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.
Meh. I leave it to you. I'll merge as-is and we can always iterate
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.
Looks good. Before merging, just wanted to double check your thoughts on the Drop
@bors r+ |
☀️ Test successful - checks-actions |
9 commits in 1cd6d3803dfb0b342272862a8590f5dfc9f72573..a5d47a72595dd6fbe7d4e4f6ec20dc5fe724edd1 2023-01-12 18:40:36 +0000 to 2023-01-16 18:51:50 +0000 - Add network container tests (rust-lang/cargo#11583) - Show progress of crates.io index update even `net.git-fetch-with-cli` option enabled (rust-lang/cargo#11579) - `cargo metadata` supports artifact dependencies (rust-lang/cargo#11550) - fix(docs): add required "inherits" option to example profile (rust-lang/cargo#11504) - add documentation that SSH markers aren't supported (rust-lang/cargo#11586) - Fix typo (rust-lang/cargo#11585) - Enable source_config_env test on Windows (rust-lang/cargo#11582) - Support `codegen-backend` and `rustflags` in profiles in config file (rust-lang/cargo#11562) - ci: reflect to clap updates (rust-lang/cargo#11578)
Update cargo 9 commits in 1cd6d3803dfb0b342272862a8590f5dfc9f72573..a5d47a72595dd6fbe7d4e4f6ec20dc5fe724edd1 2023-01-12 18:40:36 +0000 to 2023-01-16 18:51:50 +0000 - Add network container tests (rust-lang/cargo#11583) - Show progress of crates.io index update even `net.git-fetch-with-cli` option enabled (rust-lang/cargo#11579) - `cargo metadata` supports artifact dependencies (rust-lang/cargo#11550) - fix(docs): add required "inherits" option to example profile (rust-lang/cargo#11504) - add documentation that SSH markers aren't supported (rust-lang/cargo#11586) - Fix typo (rust-lang/cargo#11585) - Enable source_config_env test on Windows (rust-lang/cargo#11582) - Support `codegen-backend` and `rustflags` in profiles in config file (rust-lang/cargo#11562) - ci: reflect to clap updates (rust-lang/cargo#11578) r? `@ghost`
This adds some tests which use Docker containers to provide HTTPS and SSH servers. This should help with validating that Cargo's networking and security are working correctly. It can also potentially be used in the future for other tests that require more complex setups.
These tests are only run on Linux in CI. macOS does not have Docker there, and the Windows Docker does not support Linux containers. The tests should work on macOS if you run them locally with Docker Desktop installed. The SSH tests do not work on Windows due to issues with ssh-agent, but the HTTPS tests should work with Docker Desktop.
These tests require an opt-in environment variable to run:
CARGO_PUBLIC_NETWORK_TESTS=1
— This is for tests that contact the public internet.CARGO_CONTAINER_TESTS=1
— This is for tests that use Docker.