Skip to content

Commit 2f416d3

Browse files
Fix flaky WeightedRoutingIT (opensearch-project#19032)
Signed-off-by: guojialiang <[email protected]>
1 parent a6b6ded commit 2f416d3

File tree

1 file changed

+44
-29
lines changed

1 file changed

+44
-29
lines changed

server/src/internalClusterTest/java/org/opensearch/cluster/routing/WeightedRoutingIT.java

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.List;
3535
import java.util.Map;
3636
import java.util.Set;
37+
import java.util.concurrent.TimeUnit;
3738
import java.util.stream.Collectors;
3839
import java.util.stream.Stream;
3940

@@ -688,38 +689,52 @@ public void testClusterHealthResponseWithEnsureNodeWeighedInParam() throws Excep
688689
logger.info("--> network disruption is started");
689690
networkDisruption.startDisrupting();
690691

691-
// wait for leader checker to fail
692-
Thread.sleep(13000);
693-
694-
// Check cluster health for weighed in node when cluster manager is not discovered, health check should
695-
// return a response with 503 status code
696-
assertThrows(
697-
ClusterManagerNotDiscoveredException.class,
698-
() -> client(nodes_in_zone_a.get(0)).admin().cluster().prepareHealth().setLocal(true).setEnsureNodeWeighedIn(true).get()
699-
);
700-
701-
// Check cluster health for weighed away node when cluster manager is not discovered, health check should
702-
// return a response with 503 status code
703-
assertThrows(
704-
ClusterManagerNotDiscoveredException.class,
705-
() -> client(nodes_in_zone_c.get(0)).admin().cluster().prepareHealth().setLocal(true).setEnsureNodeWeighedIn(true).get()
706-
);
692+
assertBusy(() -> {
693+
// Check cluster health for weighed in node when cluster manager is not discovered, health check should
694+
// return a response with 503 status code
695+
assertThrows(
696+
ClusterManagerNotDiscoveredException.class,
697+
() -> client(nodes_in_zone_a.get(0)).admin().cluster().prepareHealth().setLocal(true).setEnsureNodeWeighedIn(true).get()
698+
);
699+
700+
// Check cluster health for weighed away node when cluster manager is not discovered, health check should
701+
// return a response with 503 status code
702+
assertThrows(
703+
ClusterManagerNotDiscoveredException.class,
704+
() -> client(nodes_in_zone_c.get(0)).admin().cluster().prepareHealth().setLocal(true).setEnsureNodeWeighedIn(true).get()
705+
);
706+
}, 1, TimeUnit.MINUTES);
707+
708+
logger.info("--> stop network disruption");
707709
networkDisruption.stopDisrupting();
708-
Thread.sleep(1000);
709710

710-
// delete weights
711-
ClusterDeleteWeightedRoutingResponse deleteResponse = client().admin().cluster().prepareDeleteWeightedRouting().setVersion(0).get();
712-
assertTrue(deleteResponse.isAcknowledged());
711+
assertBusy(() -> {
712+
// delete weights
713+
ClusterDeleteWeightedRoutingResponse deleteResponse = client().admin()
714+
.cluster()
715+
.prepareDeleteWeightedRouting()
716+
.setVersion(0)
717+
.get();
718+
assertTrue(deleteResponse.isAcknowledged());
713719

714-
// Check local cluster health
715-
nodeLocalHealth = client(nodes_in_zone_c.get(0)).admin()
716-
.cluster()
717-
.prepareHealth()
718-
.setLocal(true)
719-
.setEnsureNodeWeighedIn(true)
720-
.get();
721-
assertFalse(nodeLocalHealth.isTimedOut());
722-
assertTrue(nodeLocalHealth.hasDiscoveredClusterManager());
720+
ClusterHealthResponse clusterHealthResponse = client().admin()
721+
.cluster()
722+
.prepareHealth()
723+
.setWaitForNodes("4")
724+
.execute()
725+
.actionGet();
726+
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
727+
728+
// Check local cluster health
729+
clusterHealthResponse = client(nodes_in_zone_c.get(0)).admin()
730+
.cluster()
731+
.prepareHealth()
732+
.setLocal(true)
733+
.setEnsureNodeWeighedIn(true)
734+
.get();
735+
assertFalse(clusterHealthResponse.isTimedOut());
736+
assertTrue(clusterHealthResponse.hasDiscoveredClusterManager());
737+
}, 1, TimeUnit.MINUTES);
723738
}
724739

725740
public void testReadWriteWeightedRoutingMetadataOnNodeRestart() throws Exception {

0 commit comments

Comments
 (0)