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

test: make less likely that test run into :eaddrinuse failure locally #419

Merged
merged 2 commits into from
Nov 13, 2024

Conversation

grzuy
Copy link
Contributor

@grzuy grzuy commented Nov 13, 2024

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 🙂

@@ -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})
Copy link
Owner

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.

Copy link
Contributor Author

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 👏

Copy link
Owner

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

Comment on lines 59 to 60
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})
Copy link
Owner

Choose a reason for hiding this comment

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

ibid.

@mtrudel mtrudel merged commit 4e145b8 into mtrudel:main Nov 13, 2024
25 of 27 checks passed
Comment on lines +28 to +30
{:ok, {address, port}} =
start_supervised!({Bandit, scheme: :http, plug: __MODULE__, port: 0})
|> ThousandIsland.listener_info()
Copy link
Owner

Choose a reason for hiding this comment

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

nice pattern 🚀 !

@grzuy grzuy deleted the test-port branch November 13, 2024 15:59
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