Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@

package org.apache.geode.redis.internal.executor.pubsub;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.commons.lang3.SystemUtils;
import org.apache.logging.log4j.Logger;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;

import org.apache.geode.NativeRedisTestRule;
Expand All @@ -31,52 +25,20 @@
public class PubSubNativeRedisAcceptanceTest extends AbstractPubSubIntegrationTest {

private static final Logger logger = LogService.getLogger();
private static long socketTimeWaitMsec = 240000;

@ClassRule
public static NativeRedisTestRule redis = new NativeRedisTestRule();

@BeforeClass
public static void runOnce() throws IOException {
if (SystemUtils.IS_OS_LINUX) {
try {
String line = getCommandOutput("cat", "/proc/sys/net/ipv4/tcp_fin_timeout");
socketTimeWaitMsec = Long.parseLong(line.trim());
} catch (NumberFormatException | IOException ignored) {
}
} else if (SystemUtils.IS_OS_MAC) {
try {
String line = getCommandOutput("sysctl", "net.inet.tcp.msl");
String[] parts = line.split(":");
if (parts.length == 2) {
socketTimeWaitMsec = 2 * Long.parseLong(parts[1].trim());
}
} catch (NumberFormatException | IOException ignored) {
}
}
// Just leave timeout at the default if it's some other OS or there's a problem getting OS value
}

private static String getCommandOutput(String... commandStringElements) throws IOException {
Process process = new ProcessBuilder(commandStringElements).start();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()))) {
return reader.readLine();
} finally {
// Probably overkill but ensures test leaves no orphaned processes
process.destroy();
}
}

@AfterClass
public static void cleanup() throws InterruptedException {
// This test consumes a lot of sockets and any subsequent tests may fail because of spurious
// bind exceptions. Even though sockets are closed, they will remain in TIME_WAIT state so we
// need to wait for that to clear up. It shouldn't take more than a minute or so.
// For now a thread sleep is the simplest way to wait for the sockets to be out of the TIME_WAIT
// state. The default timeout of 240 sec was chosen because that is the default duration for
// TIME_WAIT on Windows. The timeouts for both mac and linux are significantly shorter.
Thread.sleep(socketTimeWaitMsec);
// There will be a better solution for this from GEODE-9495, but for now a thread sleep is the
// simplest way to wait for the sockets to be out of the TIME_WAIT state. The timeout of 240 sec
// was chosen because that is the default duration for TIME_WAIT on Windows. The timeouts for
// both mac and linux are significantly shorter.
Thread.sleep(240000);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about configuring the host machines to cycle out of TIME_WAT faster and/or increasing the ephemeral port range?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think the plan is to reintroduce the changes being reverted in this PR shortly, this commit has broken our acceptance tests so we're just removing it from develop to unblock the pipeline.

}

@Override
Expand Down