Skip to content

Commit 0c37705

Browse files
ankitkalashiv0408
authored andcommitted
Flaky RemoteClustersIT: Add assert busy to avoid race condition (opensearch-project#11057)
Signed-off-by: Ankit Kala <[email protected]> Signed-off-by: Shivansh Arora <[email protected]>
1 parent c56186e commit 0c37705

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

qa/remote-clusters/src/test/java/org/opensearch/cluster/remote/test/RemoteClustersIT.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@
4242
import org.opensearch.client.cluster.RemoteInfoRequest;
4343
import org.opensearch.client.indices.CreateIndexRequest;
4444
import org.opensearch.common.settings.Settings;
45+
import org.opensearch.common.unit.TimeValue;
4546
import org.opensearch.common.xcontent.XContentFactory;
4647
import org.junit.After;
4748
import org.junit.Before;
4849

4950
import java.io.IOException;
51+
import java.util.concurrent.TimeUnit;
5052

5153

5254
public class RemoteClustersIT extends AbstractMultiClusterRemoteTestCase {
@@ -112,7 +114,7 @@ public void testSniffModeConnectionFails() throws IOException {
112114
assertFalse(rci.isConnected());
113115
}
114116

115-
public void testHAProxyModeConnectionWorks() throws IOException {
117+
public void testHAProxyModeConnectionWorks() throws Exception {
116118
String proxyAddress = "haproxy:9600";
117119
logger.info("Configuring remote cluster [{}]", proxyAddress);
118120
ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest().persistentSettings(Settings.builder()
@@ -121,12 +123,14 @@ public void testHAProxyModeConnectionWorks() throws IOException {
121123
.build());
122124
assertTrue(cluster1Client().cluster().putSettings(request, RequestOptions.DEFAULT).isAcknowledged());
123125

124-
RemoteConnectionInfo rci = cluster1Client().cluster().remoteInfo(new RemoteInfoRequest(), RequestOptions.DEFAULT).getInfos().get(0);
125-
logger.info("Connection info: {}", rci);
126-
if (!rci.isConnected()) {
127-
logger.info("Cluster health: {}", cluster1Client().cluster().health(new ClusterHealthRequest(), RequestOptions.DEFAULT));
128-
}
129-
assertTrue(rci.isConnected());
126+
assertBusy(() -> {
127+
RemoteConnectionInfo rci = cluster1Client().cluster().remoteInfo(new RemoteInfoRequest(), RequestOptions.DEFAULT).getInfos().get(0);
128+
logger.info("Connection info: {}", rci);
129+
if (!rci.isConnected()) {
130+
logger.info("Cluster health: {}", cluster1Client().cluster().health(new ClusterHealthRequest(), RequestOptions.DEFAULT));
131+
}
132+
assertTrue(rci.isConnected());
133+
}, 10, TimeUnit.SECONDS);
130134

131135
assertEquals(2L, cluster1Client().search(
132136
new SearchRequest("haproxynosn:test2"), RequestOptions.DEFAULT).getHits().getTotalHits().value);

server/src/main/java/org/opensearch/transport/ProxyConnectionStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public void onResponse(Void v) {
309309

310310
@Override
311311
public void onFailure(Exception e) {
312-
logger.debug(
312+
logger.error(
313313
new ParameterizedMessage(
314314
"failed to open remote connection [remote cluster: {}, address: {}]",
315315
clusterAlias,

server/src/main/java/org/opensearch/transport/RemoteClusterService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ protected void updateRemoteCluster(String clusterAlias, Settings settings) {
270270
// are on the cluster state thread and our custom future implementation will throw an
271271
// assertion.
272272
if (latch.await(10, TimeUnit.SECONDS) == false) {
273-
logger.warn("failed to connect to new remote cluster {} within {}", clusterAlias, TimeValue.timeValueSeconds(10));
273+
logger.error("failed to connect to new remote cluster {} within {}", clusterAlias, TimeValue.timeValueSeconds(10));
274274
}
275275
} catch (InterruptedException e) {
276276
Thread.currentThread().interrupt();

0 commit comments

Comments
 (0)