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

bind to an unused port in integration tests #446

Merged
merged 2 commits into from
Apr 24, 2020

Conversation

jbr
Copy link
Member

@jbr jbr commented Apr 21, 2020

Prior to this PR, if a machine has a server running on any of the ports used for testing (808x), tests would fail in unclear ways. Because socket reuse flags are platform dependent, this PR finds an unused port by temporarily binding to port 0 and using the assigned port.

Copy link
Member

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

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

Few nits, but otherwise this looks 💯

@@ -67,22 +68,23 @@ const TEXT: &'static str = concat![

#[async_std::test]
async fn chunked_large() -> Result<(), http_types::Error> {
let server = task::spawn(async {
let bind = test_utils::determine_port_to_bind().await;
Copy link
Member

Choose a reason for hiding this comment

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

Can we rename the bind variable to port?

Copy link
Member Author

Choose a reason for hiding this comment

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

would socket_addr work? I initially had port (as still remains in the function name, which will also be fixed), but it's both localhost as well as the port

@@ -0,0 +1,7 @@
pub async fn determine_port_to_bind() -> async_std::net::SocketAddr {
Copy link
Member

@yoshuawuyts yoshuawuyts Apr 22, 2020

Choose a reason for hiding this comment

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

A more concise name would be find_port, would you mind changing that?

Copy link
Member Author

Choose a reason for hiding this comment

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

as with above comment, would find_socket_addr be reasonably concise and clear? it's really something like "find a port and return a socket addr with that port" but that's awkward af

and rename `bind` variable names to `port`
Copy link
Member

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

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

Thanks heaps!

@yoshuawuyts yoshuawuyts merged commit 588d2f1 into http-rs:master Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants