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

added check for open port before creating test server. #769

Merged
merged 2 commits into from
Nov 12, 2018

Conversation

littleaj
Copy link
Contributor

@littleaj littleaj commented Nov 9, 2018

This makes the tests a bit more reliable.

@littleaj littleaj added this to the 2.2.1 milestone Nov 9, 2018
@littleaj littleaj self-assigned this Nov 9, 2018
Copy link
Contributor

@dhaval24 dhaval24 left a comment

Choose a reason for hiding this comment

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

Hey @littleaj I think either I am confused and don't fully understand the purpose or may be you need to consider fixing the logic :). Please let me know either ways and I can unblock you.

Copy link
Contributor

@dhaval24 dhaval24 left a comment

Choose a reason for hiding this comment

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

Few best practice suggestions. It would be awesome if you can make those changes. Rest looks good.

private int Min = 1050;
private int Max = 15000;
private int portNumber = Min + (int)(Math.random() * ((Max - Min) + 1));
private final int Min = 1050;
Copy link
Contributor

Choose a reason for hiding this comment

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

@littleaj can you please adhere to camelCase for varable names here. I know you didn't made this variable but since you touched this part of the code better that we can clean up if possible.


public JettyTestServer() {
// try 256 times for ports
int initialPortNumber = Min + (int)(Math.random() * ((Max - Min) + 1));
Copy link
Contributor

@dhaval24 dhaval24 Nov 10, 2018

Choose a reason for hiding this comment

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

A standard way / best practice in java to get random integer within the range is this:

import java.util.concurrent.ThreadLocalRandom;

// nextInt is normally exclusive of the top value,
// so add 1 to make it inclusive
int randomNum = ThreadLocalRandom.current().nextInt(min, max + 1);

Reference: https://stackoverflow.com/questions/363681/how-to-generate-random-integers-within-a-specific-range-in-java

We don't need to reproduce the results, so seed of random doesn't really matter.

@littleaj it would be great if you can change this one as bonus!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this is test code, so I'm not really worried about this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool :) no worries. Please proceed with merging.

@littleaj littleaj merged commit d774bec into master Nov 12, 2018
@littleaj littleaj deleted the fixJettyBindTest branch November 12, 2018 21:15
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