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: avoid getFreePort collisions #4366

Merged

Conversation

ndr-brt
Copy link
Member

@ndr-brt ndr-brt commented Jul 17, 2024

What this PR changes/adds

Add an ALREADY_RETURNED HashSet to ensure that the port generated by getFreePort is not already returned.

Why it does that

Avoid possible collisions.

Further notes

  • changed the "incremental" port generation to the complete randomic. Looking at the tests they are always calling the getFreePort without arguments, that is generating a random number anyway, so the "efficiency" of using the next number instead is pretty negligible.

Linked Issue(s)

Closes #4365

Please be sure to take a look at the contributing guidelines and our etiquette for pull requests.

@ndr-brt ndr-brt added the refactoring Cleaning up code and dependencies label Jul 17, 2024
@ndr-brt ndr-brt force-pushed the 4365-avoid-getfreeport-collisions branch from 6817184 to 433f7df Compare July 17, 2024 14:08
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 74.91%. Comparing base (7f20ba5) to head (433f7df).
Report is 362 commits behind head on main.

Files Patch % Lines
...b/src/main/java/org/eclipse/edc/util/io/Ports.java 90.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4366      +/-   ##
==========================================
+ Coverage   71.74%   74.91%   +3.17%     
==========================================
  Files         919     1066     +147     
  Lines       18457    21383    +2926     
  Branches     1037     1171     +134     
==========================================
+ Hits        13242    16020    +2778     
- Misses       4756     4839      +83     
- Partials      459      524      +65     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ndr-brt ndr-brt merged commit 980f10f into eclipse-edc:main Jul 17, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Cleaning up code and dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getFreePort collisions
3 participants