Skip to content

Commit 8969c85

Browse files
committed
Fix timeout in testDowngradeRemoteClusterToBasic (#52322)
- ESCCRRestTestCase#ensureYellow does not work well with assertBusy - Increases timeout to 60s Closes #52036
1 parent 41731c1 commit 8969c85

File tree

3 files changed

+45
-29
lines changed

3 files changed

+45
-29
lines changed

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public void initClient() throws IOException {
182182
assert hasXPack != null;
183183
assert nodeVersions != null;
184184
}
185-
185+
186186
/**
187187
* Helper class to check warnings in REST responses with sensitivity to versions
188188
* used in the target cluster.
@@ -191,26 +191,26 @@ public static class VersionSensitiveWarningsHandler implements WarningsHandler {
191191
Set<String> requiredSameVersionClusterWarnings = new HashSet<>();
192192
Set<String> allowedWarnings = new HashSet<>();
193193
final Set<Version> testNodeVersions;
194-
194+
195195
public VersionSensitiveWarningsHandler(Set<Version> nodeVersions) {
196196
this.testNodeVersions = nodeVersions;
197197
}
198198

199199
/**
200200
* Adds to the set of warnings that are all required in responses if the cluster
201-
* is formed from nodes all running the exact same version as the client.
201+
* is formed from nodes all running the exact same version as the client.
202202
* @param requiredWarnings a set of required warnings
203203
*/
204204
public void current(String... requiredWarnings) {
205205
requiredSameVersionClusterWarnings.addAll(Arrays.asList(requiredWarnings));
206206
}
207207

208208
/**
209-
* Adds to the set of warnings that are permissible (but not required) when running
209+
* Adds to the set of warnings that are permissible (but not required) when running
210210
* in mixed-version clusters or those that differ in version from the test client.
211211
* @param allowedWarnings optional warnings that will be ignored if received
212212
*/
213-
public void compatible(String... allowedWarnings) {
213+
public void compatible(String... allowedWarnings) {
214214
this.allowedWarnings.addAll(Arrays.asList(allowedWarnings));
215215
}
216216

@@ -231,13 +231,13 @@ public boolean warningsShouldFailRequest(List<String> warnings) {
231231
return false;
232232
}
233233
}
234-
234+
235235
private boolean isExclusivelyTargetingCurrentVersionCluster() {
236236
assertFalse("Node versions running in the cluster are missing", testNodeVersions.isEmpty());
237-
return testNodeVersions.size() == 1 &&
237+
return testNodeVersions.size() == 1 &&
238238
testNodeVersions.iterator().next().equals(Version.CURRENT);
239-
}
240-
239+
}
240+
241241
}
242242

243243
/**
@@ -250,14 +250,14 @@ private boolean isExclusivelyTargetingCurrentVersionCluster() {
250250
public static RequestOptions expectWarnings(String... warnings) {
251251
return expectVersionSpecificWarnings(consumer -> consumer.current(warnings));
252252
}
253-
253+
254254
public static RequestOptions expectVersionSpecificWarnings(Consumer<VersionSensitiveWarningsHandler> expectationsSetter) {
255255
Builder builder = RequestOptions.DEFAULT.toBuilder();
256256
VersionSensitiveWarningsHandler warningsHandler = new VersionSensitiveWarningsHandler(nodeVersions);
257257
expectationsSetter.accept(warningsHandler);
258258
builder.setWarningsHandler(warningsHandler);
259259
return builder.build();
260-
}
260+
}
261261

262262
/**
263263
* Construct an HttpHost from the given host and port
@@ -442,7 +442,7 @@ private void wipeCluster() throws Exception {
442442
// Cleanup rollup before deleting indices. A rollup job might have bulks in-flight,
443443
// so we need to fully shut them down first otherwise a job might stall waiting
444444
// for a bulk to finish against a non-existing index (and then fail tests)
445-
//
445+
//
446446
// Rollups were introduced in 6.3.0 so any cluster that contains older
447447
// nodes won't be able to do *anything* with rollups, including cleanup.
448448
if (hasXPack && nodeVersions.first().onOrAfter(Version.V_6_3_0)
@@ -777,17 +777,31 @@ protected static void assertOK(Response response) {
777777
* @param index index to test for
778778
**/
779779
protected static void ensureGreen(String index) throws IOException {
780-
Request request = new Request("GET", "/_cluster/health/" + index);
781-
request.addParameter("wait_for_status", "green");
782-
request.addParameter("wait_for_no_relocating_shards", "true");
783-
request.addParameter("timeout", "70s");
784-
request.addParameter("level", "shards");
780+
ensureHealth(index, (request) -> {
781+
request.addParameter("wait_for_status", "green");
782+
request.addParameter("wait_for_no_relocating_shards", "true");
783+
request.addParameter("timeout", "70s");
784+
request.addParameter("level", "shards");
785+
});
786+
}
787+
788+
protected static void ensureHealth(Consumer<Request> requestConsumer) throws IOException {
789+
ensureHealth("", requestConsumer);
790+
}
791+
792+
protected static void ensureHealth(String index, Consumer<Request> requestConsumer) throws IOException {
793+
ensureHealth(client(), index, requestConsumer);
794+
}
795+
796+
protected static void ensureHealth(RestClient client, String index, Consumer<Request> requestConsumer) throws IOException {
797+
Request request = new Request("GET", "/_cluster/health" + (index.trim().isEmpty() ? "" : "/" + index));
798+
requestConsumer.accept(request);
785799
try {
786-
client().performRequest(request);
800+
client.performRequest(request);
787801
} catch (ResponseException e) {
788802
if (e.getResponse().getStatusLine().getStatusCode() == HttpStatus.SC_REQUEST_TIMEOUT) {
789803
try {
790-
final Response clusterStateResponse = client().performRequest(new Request("GET", "/_cluster/state"));
804+
final Response clusterStateResponse = client.performRequest(new Request("GET", "/_cluster/state?pretty"));
791805
fail("timed out waiting for green state for index [" + index + "] " +
792806
"cluster state [" + EntityUtils.toString(clusterStateResponse.getEntity()) + "]");
793807
} catch (Exception inner) {

x-pack/plugin/ccr/qa/downgrade-to-basic-license/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Iterator;
1919
import java.util.List;
2020
import java.util.Map;
21+
import java.util.concurrent.TimeUnit;
2122

2223
import static org.elasticsearch.common.xcontent.ObjectPath.eval;
2324
import static org.hamcrest.Matchers.containsString;
@@ -46,7 +47,7 @@ public void testDowngradeRemoteClusterToBasic() throws Exception {
4647
assertBusy(() -> {
4748
ensureYellow(index1);
4849
verifyDocuments(index1, 5, "filtered_field:true");
49-
});
50+
}, 60, TimeUnit.SECONDS);
5051

5152
String index2 = "logs-20190102";
5253
try (RestClient leaderClient = buildLeaderClient()) {
@@ -101,7 +102,7 @@ public void testDowngradeRemoteClusterToBasic() throws Exception {
101102
"the license mode [BASIC] on cluster [leader_cluster] does not enable [ccr]"));
102103
});
103104
}
104-
});
105+
}, 60, TimeUnit.SECONDS);
105106

106107
// Manually following index2 also does not work after the downgrade:
107108
Exception e = expectThrows(ResponseException.class, () -> followIndex("leader_cluster", index2));

x-pack/plugin/ccr/qa/src/main/java/org/elasticsearch/xpack/ccr/ESCCRRestTestCase.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,15 @@ protected static void ensureYellow(final String index) throws IOException {
208208
}
209209

210210
protected static void ensureYellow(final String index, final RestClient client) throws IOException {
211-
final Request request = new Request("GET", "/_cluster/health/" + index);
212-
request.addParameter("wait_for_status", "yellow");
213-
request.addParameter("wait_for_active_shards", "1");
214-
request.addParameter("wait_for_no_relocating_shards", "true");
215-
request.addParameter("wait_for_no_initializing_shards", "true");
216-
request.addParameter("timeout", "5s");
217-
request.addParameter("level", "shards");
218-
client.performRequest(request);
211+
ensureHealth(client, index, request -> {
212+
request.addParameter("wait_for_status", "yellow");
213+
request.addParameter("wait_for_active_shards", "1");
214+
request.addParameter("wait_for_no_relocating_shards", "true");
215+
// follower index can be yellow even when its primary shards are still initializing as we bootstrap them using snapshot/restore.
216+
request.addParameter("wait_for_no_initializing_shards", "true");
217+
request.addParameter("timeout", "5s");
218+
request.addParameter("level", "shards");
219+
});
219220
}
220221

221222
protected int countCcrNodeTasks() throws IOException {

0 commit comments

Comments
 (0)