-
Notifications
You must be signed in to change notification settings - Fork 6
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 listen_tcp_on_free_port to return a test port #41
Conversation
25261c1
to
4b8a43c
Compare
4b8a43c
to
e591dd5
Compare
Reduce a bunch of duplicated boilerplate code
Previously in tests downstream ohttp_relay was initiated with a port that may no longer be free by the time it got bound. By having this code bind on and return the port the indirection is removed.
e591dd5
to
d8f7578
Compare
NGINX was also returning before binding to the port, sometimes leading to port contention with other test services Fix by waiting for it to connect before attempting to start other services
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.
not sure about the last commit, i'd prefer if start_nginx
returned a Result<NginxProcess>
, but i think it's fine to merge this so that listen_tcp_on_free_port
is exposed and followup with a refactor, since the new behavior is still an improvement on the old
while start.elapsed() < timeout { | ||
if let Ok(_) = std::net::TcpStream::connect(format!("127.0.0.1:{}", n_https_port)) { | ||
break; | ||
} | ||
tokio::time::sleep(std::time::Duration::from_millis(100)).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.
happy path and error path are not distinguished, which is strange to me... if the timeout elapses and nginx was not yet listening, why proceed?
e04c6ce
to
d8f7578
Compare
I accidentally pushed the fix here but will open it in a new PR. that was a brain fart, obviously we want to separate the paths and return an error if we fail. I'm going to merge the approved commit to enable forward motion |
Previously in tests downstream ohttp_relay was initiated with a port
that may no longer be free by the time it got bound. By having this
code bind on and return the port the indirection is removed.
I also found that the way I was having NGINX listen on a free port may also have led to the same problem, so the 3rd commit ensures NGINX is bound before the ohttp_relay tries to get a free port.