-
Notifications
You must be signed in to change notification settings - Fork 89
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
test: make less likely that test run into :eaddrinuse failure locally #419
Conversation
test/bandit/server_test.exs
Outdated
@@ -25,7 +25,7 @@ defmodule ServerTest do | |||
end | |||
|
|||
test "server logs connection error detail log at startup" do | |||
pid = start_supervised!({Bandit, scheme: :http, plug: __MODULE__}) | |||
pid = start_supervised!({Bandit, scheme: :http, plug: __MODULE__, port: 40_000}) |
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.
You can pass a value of 0
for port and it will pick an open port automatically.
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.
Oh, cool, like gen_tcp
👏
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.
Yup, exactly. Bandit is just a thin layer on Thousand Island which is just a thin layer on gen_tcp. It's all transparent
test/bandit/server_test.exs
Outdated
start_supervised({Bandit, plug: __MODULE__, port: 4000}) | ||
start_supervised({Bandit, plug: __MODULE__, port: 4001}) | ||
start_supervised({Bandit, plug: __MODULE__, port: 40_000}) | ||
start_supervised({Bandit, plug: __MODULE__, port: 40_001}) |
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.
ibid.
{:ok, {address, port}} = | ||
start_supervised!({Bandit, scheme: :http, plug: __MODULE__, port: 0}) | ||
|> ThousandIsland.listener_info() |
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 pattern 🚀 !
Very minor dev ergnomics thing.
When working on previous PRs, I sometimes got eaddrinuse locally while occasionally running bandit test because of having other phoenix apps on default 4000 on the side 🙂