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

make TestGetHostPortRange unit test deterministic #3587

Merged
merged 1 commit into from
Feb 27, 2023

Conversation

singholt
Copy link
Contributor

@singholt singholt commented Feb 22, 2023

Summary

make TestGetHostPortRange unit test deterministic

I noticed that the TestGetHostPortRange unit test relies on the underlying host's port availability. example failure

2023-02-22T08:49:37.6412749Z === RUN   TestGetHostPortRange/tcp_protocol,_contiguous_hostPortRange_found
2023-02-22T08:49:37.6412935Z     ephemeral_ports_test.go:144: 
2023-02-22T08:49:37.6413203Z         	Error Trace:	ephemeral_ports_test.go:144
2023-02-22T08:49:37.6413427Z         	Error:      	Not equal: 
2023-02-22T08:49:37.6413669Z         	            	expected: 40010
2023-02-22T08:49:37.6413896Z         	            	actual  : 40012
2023-02-22T08:49:37.6414282Z         	Test:       	

The getHostPortRange method does a net.Listen/net.ListenPacket calls on the host to check if a port is available. In the unit test, we check if the assigned ports matches an expected set of ports. This leads to it occasionally failing on PRs GH workflow, depending on whether a port is available at that point in time.

Implementation details

This PR refactors the getHostPortRange method and mocks the part where we do the port check on the host, in the unit test.

Testing

Existing unit tests succeed.

New tests cover the changes: no

Description for the changelog

make TestGetHostPortRange unit test deterministic

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@singholt singholt changed the title make TestGetHostPortRange unit test deterministic make TestGetHostPortRange unit test deterministic Feb 22, 2023
@singholt singholt changed the base branch from master to dev February 22, 2023 10:35
@singholt singholt changed the title make TestGetHostPortRange unit test deterministic [wip] make TestGetHostPortRange unit test deterministic Feb 22, 2023
@singholt singholt force-pushed the make-test-deterministic branch 2 times, most recently from 3b58e7d to 920146c Compare February 22, 2023 10:43
@singholt singholt force-pushed the make-test-deterministic branch from 920146c to 064dcf1 Compare February 22, 2023 18:29
@singholt singholt force-pushed the make-test-deterministic branch from 064dcf1 to aa97e3d Compare February 22, 2023 22:21
@singholt singholt changed the title [wip] make TestGetHostPortRange unit test deterministic make TestGetHostPortRange unit test deterministic Feb 24, 2023
@singholt singholt marked this pull request as ready for review February 24, 2023 18:46
@singholt singholt requested a review from a team as a code owner February 24, 2023 18:46
Realmonia
Realmonia previously approved these changes Feb 24, 2023
Copy link
Contributor

@Realmonia Realmonia left a comment

Choose a reason for hiding this comment

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

Looks good to me. Can you give an example around why sometimes the specific port is not available?

@singholt
Copy link
Contributor Author

singholt commented Feb 24, 2023

Looks good to me. Can you give an example around why sometimes the specific port is not available?

thanks for reviewing this PR! I am not sure how GH workflows run unit tests and what setup is shared across multiple runs. This PR is just based on observations from previous GH workflow unit test failures, like the one I linked in the description.

I suspect if multiple PRs run tests together, they may be running on the same host at the same time. This is just my guess. This PR doesn't change any existing functionality anyways, just mocks the runtime check which it should.

@Realmonia
Copy link
Contributor

Looks good to me. Can you give an example around why sometimes the specific port is not available?

thanks for reviewing this PR! I am not sure how GH workflows run unit tests and what setup is shared across multiple runs. This PR is just based on observations from previous GH workflow unit test failures, like the one I linked in the description.

I suspect if multiple PRs run tests together, they may be running on the same host at the same time. This is just my guess. This PR doesn't change any existing functionality anyways, just mocks the runtime check which it should.

Sounds good

@singholt singholt force-pushed the make-test-deterministic branch 3 times, most recently from 26e539d to 2ddaa56 Compare February 27, 2023 18:25
@singholt singholt force-pushed the make-test-deterministic branch from 2ddaa56 to ba3d07f Compare February 27, 2023 18:51
@singholt singholt merged commit cea7a56 into aws:dev Feb 27, 2023
@singholt singholt deleted the make-test-deterministic branch February 27, 2023 20:21
@mye956 mye956 mentioned this pull request Mar 7, 2023
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.

4 participants