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

Expand tests #67

Closed
wants to merge 2 commits into from
Closed

Expand tests #67

wants to merge 2 commits into from

Conversation

petroav
Copy link

@petroav petroav commented Jan 24, 2019

No description provided.

"go-reuseport requires go >= 1.11"

;
package reuseport
Copy link
Author

Choose a reason for hiding this comment

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

Added the package keyword because gx-go would complain and make deps would fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems great. @Stebalien will know if this is appropriate.

Copy link
Author

Choose a reason for hiding this comment

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

👍

Copy link
Member

Choose a reason for hiding this comment

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

So, I put that where it is so "go-reuseport requires go >= 1.11" would show up in the compiler's error message. However, I can confirm that this breaks gx so that's probably good enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the error message isn't useful anymore, there's probably no point having this file anymore, unless gx is fixed or exposes a build tag of its own.

Copy link
Member

Choose a reason for hiding this comment

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

Probably. Note: there's nothing gx can do about this. Unfortunately, it has to ignore build tags (it can't know what build tags you're going to use later).

)

func testDialFromListeningPort(t *testing.T, network, host string) {
Copy link
Author

Choose a reason for hiding this comment

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

Fully removed the previous tests because they were outdated and some of their logic had been moved to interface.go.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how the new tests are better. If you want to add "udp" to the networks tested, I suggest you make a test wrapping testDialFromListeningPort(t, "udp", "localhost")

Copy link
Author

Choose a reason for hiding this comment

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

I think the new tests are better because they exercise the code via the public API. Namely I directly call Listen(network, address string), ListenPacket(network, address string), Dial(network, laddr, raddr string) and Available(). Instead the current tests instantiate their own ListenConfig and call methods on that instead of via the wrappers offered in interface.go. For this reason a large part of the code does not get exercised.

Instead of re-writing the tests, I'd be happy to rework the current testDialFromListeningPort method to make the right calls.

Copy link
Contributor

@anacrolix anacrolix left a comment

Choose a reason for hiding this comment

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

The badges, gx assertion fix, and typo are good, but the rest I think should just be an extra test for "udp", if you actually need that behaviour.

)

func testDialFromListeningPort(t *testing.T, network, host string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how the new tests are better. If you want to add "udp" to the networks tested, I suggest you make a test wrapping testDialFromListeningPort(t, "udp", "localhost")

pc, err := ListenPacket("udp", ":0")
require.NoError(t, err)
pc.Close()
func TestErrorWhenDialUnresolvable(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't a very useful test. You might test that the function returns net.UnknownNetworkError, but that's not documented.

Copy link
Author

Choose a reason for hiding this comment

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

I think it is a useful test because it ensures that Dial performs the correct error handling and doesn't swallow errors from ResolveAddr. I'd be happy to document the error handling of Dial. Or did you want this test removed?

Copy link
Member

Choose a reason for hiding this comment

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

It's useful to test all error paths. I've written if err == nil instead of if err != nil several times.

"go-reuseport requires go >= 1.11"

;
package reuseport
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems great. @Stebalien will know if this is appropriate.

network string
}

func TestResolveAddr(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't very useful.

Copy link
Author

Choose a reason for hiding this comment

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

Why do you think it's not useful? I added the test because ResolveAddr is an exported method of this package and the test verifies the method will resolve addresses for these protocols. While the test may seem silly given that we can see the implementation, its purpose is to verify behaviour offered by ResolveAddr from a user's perspective. So if someone were to refactor ResolveAddr the test would help them ensure that no functionality was lost.

@petroav
Copy link
Author

petroav commented Jan 25, 2019

@anacrolix thanks for taking the time to review my changes! The context of this PR is this issue libp2p/go-libp2p#83

@anacrolix
Copy link
Contributor

I've reworked this into #68.

@anacrolix
Copy link
Contributor

#68 merges parts of this. Recommend to open a new PR if you want to revisit testing Dial/Listen, and ResolveAddr. See also #69.

@anacrolix anacrolix closed this Jan 31, 2019
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.

3 participants