Skip to content

Commit a35e560

Browse files
authored
Test utility for POST _features/_reset (#137176)
We call `POST _features/_reset` in various places in the tests, only sometimes asserting that the response is `200 OK`. This commit extracts a utility that makes it harder to miss this assertion. It also adds the `?error_trace` parameter so that on failure the details are visible in the response.
1 parent c0a9750 commit a35e560

File tree

9 files changed

+19
-13
lines changed

9 files changed

+19
-13
lines changed

qa/system-indices/src/javaRestTest/java/org/elasticsearch/system/indices/FeatureUpgradeApiIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class FeatureUpgradeApiIT extends AbstractSystemIndicesIT {
2929

3030
@After
3131
public void resetFeatures() throws Exception {
32-
client().performRequest(new Request("POST", "/_features/_reset"));
32+
performPostFeaturesReset(client());
3333
}
3434

3535
public void testCreatingSystemIndex() throws Exception {

qa/system-indices/src/javaRestTest/java/org/elasticsearch/system/indices/NetNewSystemIndicesIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,6 @@ public void testSearch() throws Exception {
9494

9595
@After
9696
public void resetFeatures() throws Exception {
97-
client().performRequest(new Request("POST", "/_features/_reset"));
97+
performPostFeaturesReset(client());
9898
}
9999
}

qa/system-indices/src/javaRestTest/java/org/elasticsearch/system/indices/SystemAliasIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class SystemAliasIT extends AbstractSystemIndicesIT {
2626

2727
@After
2828
public void resetFeatures() throws Exception {
29-
client().performRequest(new Request("POST", "/_features/_reset"));
29+
performPostFeaturesReset(client());
3030
}
3131

3232
public void testCreatingSystemIndexWithAlias() throws Exception {

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,15 @@ protected boolean preserveSearchableSnapshotsIndicesUponCompletion() {
923923
return false;
924924
}
925925

926+
/**
927+
* Invoke {@code POST /_features/_reset?error_trace} with the given {@link RestClient}.
928+
*/
929+
public static void performPostFeaturesReset(RestClient restClient) throws IOException {
930+
final var request = new Request(HttpPost.METHOD_NAME, "/_features/_reset");
931+
request.addParameter("error_trace", "true");
932+
assertOK(restClient.performRequest(request));
933+
}
934+
926935
private void wipeCluster() throws Exception {
927936
waitForClusterUpdates();
928937

@@ -949,8 +958,7 @@ private void wipeCluster() throws Exception {
949958
wipeSnapshots();
950959

951960
if (resetFeatureStates()) {
952-
final Request postRequest = new Request("POST", "/_features/_reset");
953-
cleanupClient().performRequest(postRequest);
961+
performPostFeaturesReset(cleanupClient());
954962
}
955963

956964
// wipe data streams before indices so that the backing indices for data streams are handled properly

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/integration/MlRestTestStateCleaner.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.List;
1818
import java.util.Map;
1919

20+
import static org.elasticsearch.test.rest.ESRestTestCase.performPostFeaturesReset;
2021
import static org.hamcrest.MatcherAssert.assertThat;
2122
import static org.hamcrest.Matchers.hasSize;
2223

@@ -33,7 +34,7 @@ public MlRestTestStateCleaner(Logger logger, RestClient adminClient) {
3334
public void resetFeatures() throws IOException {
3435
deletePipelinesWithInferenceProcessors();
3536
// This resets all features, not just ML, but they should have been getting reset between tests anyway so it shouldn't matter
36-
adminClient.performRequest(new Request("POST", "/_features/_reset"));
37+
performPostFeaturesReset(adminClient);
3738
}
3839

3940
@SuppressWarnings("unchecked")

x-pack/plugin/deprecation/qa/src/javaRestTest/java/org/elasticsearch/xpack/deprecation/MlDeprecationIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ protected String getTestRestCluster() {
5959

6060
@After
6161
public void resetFeatures() throws IOException {
62-
Response response = adminClient().performRequest(new Request("POST", "/_features/_reset"));
63-
assertOK(response);
62+
performPostFeaturesReset(adminClient());
6463
}
6564

6665
@Override

x-pack/plugin/ml/qa/disabled/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/MlPluginDisabledIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ public void testActionsFail() throws Exception {
7575
}
7676

7777
public void testMlFeatureReset() throws IOException {
78-
Request request = new Request("POST", "/_features/_reset");
79-
assertOK(client().performRequest(request));
78+
performPostFeaturesReset(client());
8079
}
8180

8281
@SuppressWarnings("unchecked")

x-pack/plugin/ml/qa/single-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/InferenceTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void cleanup() throws Exception {
3333
}
3434
createdPipelines.clear();
3535
waitForStats();
36-
adminClient().performRequest(new Request("POST", "/_features/_reset"));
36+
performPostFeaturesReset(adminClient());
3737
}
3838

3939
void deletePipeline(String pipelineId) throws IOException {

x-pack/plugin/transform/qa/multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TestFeatureResetIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package org.elasticsearch.xpack.transform.integration;
88

9-
import org.apache.http.client.methods.HttpPost;
109
import org.elasticsearch.client.Request;
1110
import org.elasticsearch.client.RequestOptions;
1211
import org.elasticsearch.client.Response;
@@ -95,7 +94,7 @@ public void testTransformFeatureReset() throws Exception {
9594

9695
startTransform(continuousTransformId, RequestOptions.DEFAULT);
9796

98-
assertOK(client().performRequest(new Request(HttpPost.METHOD_NAME, "/_features/_reset")));
97+
performPostFeaturesReset(client());
9998

10099
Response response = adminClient().performRequest(new Request("GET", "/_cluster/state?metric=metadata"));
101100
Map<String, Object> metadata = (Map<String, Object>) ESRestTestCase.entityAsMap(response).get("metadata");

0 commit comments

Comments
 (0)