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

GEODE-8772: Make tests assign ports #5935

Conversation

demery-pivotal
Copy link
Contributor

Some tests in ManagementRequestLoggingDistributedTest and
RestAPIsAndInterOpsDUnitTest were using the default JMX port (1099).
Some tests in TombstoneDUnitTest were using the default cache server
port (40404). When these tests run in parallel outside of docker, they
can fail to bind these ports if another test has already bound them.

These tests now assign ports via AvailablePortHelper.

Authored-by: Dale Emery demery@vmware.com

Some tests in ManagementRequestLoggingDistributedTest and
RestAPIsAndInterOpsDUnitTest were using the default JMX port (1099).
Some tests in TombstoneDUnitTest were using the default cache server
port (40404). When these tests run in parallel outside of docker, they
can fail to bind these ports if another test has already bound them.

These tests now assign ports via AvailablePortHelper.

Authored-by: Dale Emery <demery@vmware.com>
Copy link
Contributor

@dschneider-pivotal dschneider-pivotal left a comment

Choose a reason for hiding this comment

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

These changes look good. The only one I had a question about was the one that used to use "0"

Properties props = new Properties();
props.setProperty(MCAST_PORT, String.valueOf(0));
props.setProperty(LOCATORS, locators);

props.setProperty(JMX_MANAGER, "true");
props.setProperty(JMX_MANAGER_START, "true");
props.setProperty(JMX_MANAGER_PORT, "0");
props.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxManagerPort));
Copy link
Contributor

Choose a reason for hiding this comment

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

In this case you changed from "0" to using getRandomAvailableTCPPorts. I would have thought "0" is even better because using getRandomAvailableTCPPorts has a small race in which the port it hands back could end up being used by another before this thread can bind to it. I thought "0" was better because we are telling the operating system to give us an available port at the time we bind to it so we get rid of the race window. It can be hard to do in some tests when they need to know ahead of time what the actual port is. Do you know using "0" causes test issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That edit might be a mistake. My intention in this PR was to fix only uses of default ports.

Note: For this property (according to the docs) 0 means don't allow remote client connections. I'll have to look closer at what happens when 0 is specified here.

Other note: Using ephemeral ports can reduce the frequency of the race, but it doesn't eliminate it, because Geode's membership port range overlaps the ephemeral port range. So here's a troubling sequence:

  1. Component A "reserves" a port in the membership port range.
  2. Component B (perhaps running in a separate test, a separate member, or even a non-Geode process) binds an ephemeral port, and gets the "reserved" port.
  3. Component A tries to bind the port it "reserved" and fails.

I'm not sure how often this troubling sequence happens, but it does happen. Requesting a non-membership port (via AvailablePortHelper) helps by assigning ports outside the ephemeral port range.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this change is unnecessary and I've reverted it. Thanks for catching that.

@demery-pivotal demery-pivotal merged commit 964051b into apache:develop Jan 22, 2021
@demery-pivotal demery-pivotal deleted the geode-8772/make-tests-assign-ports branch January 22, 2021 17:33
Copy link
Contributor

@mhansonp mhansonp left a comment

Choose a reason for hiding this comment

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

Other than a few int's that could be final int's it looks good to me.

@@ -168,6 +168,8 @@ private CacheServer createRegionAndStartCacheServer(String[] regions, Cache cach
}

private int startManager(final String locators, final String[] regions) throws IOException {
int httpPort = getRandomAvailableTCPPort();
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 like it could be final...

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