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

[#1675][FOLLOWUP] fix(test): Fix various flaky tests #1730

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -123,6 +123,7 @@ public static String getHostIp() throws Exception {
}
return ip;
}
boolean isTestMode = Boolean.parseBoolean(System.getProperty("test.mode", "false"));
Enumeration<NetworkInterface> nif = NetworkInterface.getNetworkInterfaces();
String siteLocalAddress = null;
while (nif.hasMoreElements()) {
Expand All @@ -133,7 +134,7 @@ public static String getHostIp() throws Exception {
for (InterfaceAddress ifa : ni.getInterfaceAddresses()) {
InetAddress ia = ifa.getAddress();
InetAddress brd = ifa.getBroadcast();
if (brd == null || brd.isAnyLocalAddress()) {
if ((brd == null || brd.isAnyLocalAddress()) && !isTestMode) {
LOGGER.info(
"ip {} was filtered, because it don't have effective broadcast address",
ia.getHostAddress());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.FileWriter;
import java.io.PrintWriter;
import java.net.URI;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -132,91 +133,93 @@ public void getLostServerListTest() throws Exception {
CoordinatorConf coordinatorConf = new CoordinatorConf();
// Shorten the heartbeat time
coordinatorConf.setLong(CoordinatorConf.COORDINATOR_HEARTBEAT_TIMEOUT, 300L);
SimpleClusterManager clusterManager =
new SimpleClusterManager(coordinatorConf, new Configuration());
ServerNode sn1 = new ServerNode("sn1", "ip", 0, 100L, 50L, 20, 10, grpcTags);
ServerNode sn2 = new ServerNode("sn2", "ip", 0, 100L, 50L, 21, 10, grpcTags);
ServerNode sn3 = new ServerNode("sn3", "ip", 0, 100L, 50L, 20, 11, grpcTags);
clusterManager.add(sn1);
clusterManager.add(sn2);
clusterManager.add(sn3);
Set<String> expectedIds = Sets.newHashSet("sn1", "sn2", "sn3");
await()
.atMost(1, TimeUnit.SECONDS)
.until(
() -> {
Set<String> lostServerList =
clusterManager.getLostServerList().stream()
.map(ServerNode::getId)
.collect(Collectors.toSet());
return CollectionUtils.isEqualCollection(lostServerList, expectedIds);
});
// re-register sn3
sn3 = new ServerNode("sn3", "ip", 0, 100L, 50L, 20, 11, grpcTags);
clusterManager.add(sn3);
Set<String> expectedIdsre = Sets.newHashSet("sn1", "sn2");
await()
.atMost(1, TimeUnit.SECONDS)
.until(
() -> {
// Retrieve listed ServerNode List
Set<String> lostServerListre =
clusterManager.getLostServerList().stream()
.map(ServerNode::getId)
.collect(Collectors.toSet());
return CollectionUtils.isEqualCollection(lostServerListre, expectedIdsre);
});
try (SimpleClusterManager clusterManager =
new SimpleClusterManager(coordinatorConf, new Configuration())) {
ServerNode sn1 = new ServerNode("sn1", "ip", 0, 100L, 50L, 20, 10, grpcTags);
ServerNode sn2 = new ServerNode("sn2", "ip", 0, 100L, 50L, 21, 10, grpcTags);
ServerNode sn3 = new ServerNode("sn3", "ip", 0, 100L, 50L, 20, 11, grpcTags);
clusterManager.add(sn1);
clusterManager.add(sn2);
clusterManager.add(sn3);
Set<String> expectedIds = Sets.newHashSet("sn1", "sn2", "sn3");
await()
.atMost(1, TimeUnit.SECONDS)
.until(
() -> {
Set<String> lostServerList =
clusterManager.getLostServerList().stream()
.map(ServerNode::getId)
.collect(Collectors.toSet());
return CollectionUtils.isEqualCollection(lostServerList, expectedIds);
});
// re-register sn3
sn3 = new ServerNode("sn3", "ip", 0, 100L, 50L, 20, 11, grpcTags);
clusterManager.add(sn3);
Set<String> expectedIdsre = Sets.newHashSet("sn1", "sn2");
await()
.atMost(1, TimeUnit.SECONDS)
.until(
() -> {
// Retrieve listed ServerNode List
Set<String> lostServerListre =
clusterManager.getLostServerList().stream()
.map(ServerNode::getId)
.collect(Collectors.toSet());
return CollectionUtils.isEqualCollection(lostServerListre, expectedIdsre);
});
}
}

@Test
public void getUnhealthyServerList() throws Exception {
CoordinatorConf coordinatorConf = new CoordinatorConf();
// Shorten the heartbeat time
coordinatorConf.setLong(CoordinatorConf.COORDINATOR_HEARTBEAT_TIMEOUT, 300L);
SimpleClusterManager clusterManager =
new SimpleClusterManager(coordinatorConf, new Configuration());
ServerNode sn1 = new ServerNode("sn1", "ip", 0, 100L, 50L, 20, 10, grpcTags);
ServerNode sn2 = new ServerNode("sn2", "ip", 0, 100L, 50L, 21, 10, grpcTags);
ServerNode sn3 =
new ServerNode("sn3", "ip", 0, 100L, 50L, 20, 11, grpcTags, ServerStatus.UNHEALTHY);
ServerNode sn4 =
new ServerNode("sn4", "ip", 0, 100L, 50L, 20, 11, grpcTags, ServerStatus.UNHEALTHY);
clusterManager.add(sn1);
clusterManager.add(sn2);
clusterManager.add(sn3);
clusterManager.add(sn4);
// Analog timeout registration
Set<String> expectedIds = Sets.newHashSet("sn3", "sn4");
await()
.atMost(1, TimeUnit.SECONDS)
.until(
() -> {
Set<String> unhealthyServerList =
clusterManager.getUnhealthyServerList().stream()
.map(ServerNode::getId)
.collect(Collectors.toSet());
return CollectionUtils.isEqualCollection(unhealthyServerList, expectedIds);
});
// Register unhealthy node sn3 again
sn3 = new ServerNode("sn3", "ip", 0, 100L, 50L, 20, 11, grpcTags, ServerStatus.UNHEALTHY);
clusterManager.add(sn3);
Set<String> expectedIdsre = Sets.newHashSet("sn3");
await()
.atMost(1, TimeUnit.SECONDS)
.until(
() -> {
Set<String> unhealthyServerListre =
clusterManager.getUnhealthyServerList().stream()
.map(ServerNode::getId)
.collect(Collectors.toSet());
return CollectionUtils.isEqualCollection(unhealthyServerListre, expectedIdsre);
});
// At this point verify that sn4 is in the lost list
List<ServerNode> lostremoveunhealthy = clusterManager.getLostServerList();
Set<String> expectedIdlostremoveunhealthy = Sets.newHashSet("sn1", "sn2", "sn4");
assertEquals(
expectedIdlostremoveunhealthy,
lostremoveunhealthy.stream().map(ServerNode::getId).collect(Collectors.toSet()));
try (SimpleClusterManager clusterManager =
new SimpleClusterManager(coordinatorConf, new Configuration())) {
ServerNode sn1 = new ServerNode("sn1", "ip", 0, 100L, 50L, 20, 10, grpcTags);
ServerNode sn2 = new ServerNode("sn2", "ip", 0, 100L, 50L, 21, 10, grpcTags);
ServerNode sn3 =
new ServerNode("sn3", "ip", 0, 100L, 50L, 20, 11, grpcTags, ServerStatus.UNHEALTHY);
ServerNode sn4 =
new ServerNode("sn4", "ip", 0, 100L, 50L, 20, 11, grpcTags, ServerStatus.UNHEALTHY);
clusterManager.add(sn1);
clusterManager.add(sn2);
clusterManager.add(sn3);
clusterManager.add(sn4);
// Analog timeout registration
Set<String> expectedIds = Sets.newHashSet("sn3", "sn4");
await()
.atMost(1, TimeUnit.SECONDS)
.until(
() -> {
Set<String> unhealthyServerList =
clusterManager.getUnhealthyServerList().stream()
.map(ServerNode::getId)
.collect(Collectors.toSet());
return CollectionUtils.isEqualCollection(unhealthyServerList, expectedIds);
});
// Register unhealthy node sn3 again
sn3 = new ServerNode("sn3", "ip", 0, 100L, 50L, 20, 11, grpcTags, ServerStatus.UNHEALTHY);
clusterManager.add(sn3);
Set<String> expectedIdsre = Sets.newHashSet("sn3");
await()
.atMost(1, TimeUnit.SECONDS)
.until(
() -> {
Set<String> unhealthyServerListre =
clusterManager.getUnhealthyServerList().stream()
.map(ServerNode::getId)
.collect(Collectors.toSet());
return CollectionUtils.isEqualCollection(unhealthyServerListre, expectedIdsre);
});
// At this point verify that sn4 is in the lost list
List<ServerNode> lostremoveunhealthy = clusterManager.getLostServerList();
Set<String> expectedIdlostremoveunhealthy = Sets.newHashSet("sn1", "sn2", "sn4");
assertEquals(
expectedIdlostremoveunhealthy,
lostremoveunhealthy.stream().map(ServerNode::getId).collect(Collectors.toSet()));
}
}

@Test
Expand Down Expand Up @@ -423,11 +426,12 @@ public void testGetCorrectServerNodesWhenOneNodeRemoved() throws Exception {
public void updateExcludeNodesTest() throws Exception {
String excludeNodesFolder =
(new File(ClassLoader.getSystemResource("empty").getFile())).getParent();
String excludeNodesPath = excludeNodesFolder + "/excludeNodes";
String excludeNodesPath = Paths.get(excludeNodesFolder, "excludeNodes").toString();
CoordinatorConf ssc = new CoordinatorConf();
File excludeNodesFile = new File(excludeNodesPath);
URI excludeNodesUri = excludeNodesFile.toURI();
ssc.setString(
CoordinatorConf.COORDINATOR_EXCLUDE_NODES_FILE_PATH,
URI.create(excludeNodesPath).toString());
CoordinatorConf.COORDINATOR_EXCLUDE_NODES_FILE_PATH, excludeNodesUri.toURL().toString());
ssc.setLong(CoordinatorConf.COORDINATOR_EXCLUDE_NODES_CHECK_INTERVAL, 1000);

try (SimpleClusterManager scm = new SimpleClusterManager(ssc, new Configuration())) {
Expand Down Expand Up @@ -492,11 +496,12 @@ public void updateExcludeNodesTest() throws Exception {
public void excludeNodesNoDelayTest() throws Exception {
String excludeNodesFolder =
(new File(ClassLoader.getSystemResource("empty").getFile())).getParent();
String excludeNodesPath = excludeNodesFolder + "/excludeNodes";
String excludeNodesPath = Paths.get(excludeNodesFolder, "excludeNodes").toString();
CoordinatorConf ssc = new CoordinatorConf();
File excludeNodesFile = new File(excludeNodesPath);
URI excludeNodesUri = excludeNodesFile.toURI();
ssc.setString(
CoordinatorConf.COORDINATOR_EXCLUDE_NODES_FILE_PATH,
URI.create(excludeNodesPath).toString());
CoordinatorConf.COORDINATOR_EXCLUDE_NODES_FILE_PATH, excludeNodesUri.toURL().toString());
ssc.setLong(CoordinatorConf.COORDINATOR_EXCLUDE_NODES_CHECK_INTERVAL, 5000);

final Set<String> nodes = Sets.newHashSet("node1-1999", "node2-1999");
Expand Down
Loading
Loading