-
Notifications
You must be signed in to change notification settings - Fork 321
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
Conversation
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.
Few nits, but otherwise this looks 💯
tests/chunked-encode-large.rs
Outdated
@@ -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; |
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.
Can we rename the bind
variable to port
?
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.
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
tests/test_utils.rs
Outdated
@@ -0,0 +1,7 @@ | |||
pub async fn determine_port_to_bind() -> async_std::net::SocketAddr { |
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.
A more concise name would be find_port
, would you mind changing that?
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.
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`
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.
Thanks heaps!
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.