From 0b2b638ce452ca888a72d35e137ac8946f6f775d Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Fri, 1 Dec 2023 15:46:53 -0800 Subject: [PATCH] New QA module for heap attack tests (#102833) (#102892) The heap attack test suite is very special. It deliberately tries to take down Elasticsearch testing instances. When one of Elasticsearch testing instance is terminated, other tests will fail. This PR avoids such noise by adding a new QA module for only heap attack tests. --- .../internal/RestrictedBuildApiService.java | 1 + .../esql/qa/server/heap-attack/build.gradle | 19 ++++++++++++++ .../esql/qa/heap_attack}/HeapAttackIT.java | 25 +++++++++---------- .../esql/qa/server/multi-node/build.gradle | 2 +- 4 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 x-pack/plugin/esql/qa/server/heap-attack/build.gradle rename x-pack/plugin/esql/qa/server/{single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node => heap-attack/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/heap_attack}/HeapAttackIT.java (97%) diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/RestrictedBuildApiService.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/RestrictedBuildApiService.java index 959bfb8cd3789..3cca9fb002e37 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/RestrictedBuildApiService.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/RestrictedBuildApiService.java @@ -140,6 +140,7 @@ private static ListMultimap, String> createLegacyRestTestBasePluginUsag map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:eql:qa:mixed-node"); map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:eql:qa:multi-cluster-with-security"); map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:esql:qa:security"); + map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:esql:qa:server:heap-attack"); map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:esql:qa:server:multi-node"); map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:esql:qa:server:single-node"); map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:fleet:qa:rest"); diff --git a/x-pack/plugin/esql/qa/server/heap-attack/build.gradle b/x-pack/plugin/esql/qa/server/heap-attack/build.gradle new file mode 100644 index 0000000000000..de88fdecf2b14 --- /dev/null +++ b/x-pack/plugin/esql/qa/server/heap-attack/build.gradle @@ -0,0 +1,19 @@ +apply plugin: 'elasticsearch.legacy-yaml-rest-test' + +dependencies { + javaRestTestImplementation project(xpackModule('esql:qa:testFixtures')) +} + +restResources { + restApi { + include '_common', 'bulk', 'indices', 'esql', 'xpack', 'enrich' + } +} + +testClusters.configureEach { + numberOfNodes = 1 + testDistribution = 'DEFAULT' + setting 'xpack.license.self_generated.type', 'trial' + setting 'xpack.monitoring.collection.enabled', 'true' + setting 'xpack.security.enabled', 'false' +} diff --git a/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/HeapAttackIT.java b/x-pack/plugin/esql/qa/server/heap-attack/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/heap_attack/HeapAttackIT.java similarity index 97% rename from x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/HeapAttackIT.java rename to x-pack/plugin/esql/qa/server/heap-attack/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/heap_attack/HeapAttackIT.java index 33a6e355cb4d3..94cd6a9be76f3 100644 --- a/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/HeapAttackIT.java +++ b/x-pack/plugin/esql/qa/server/heap-attack/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/heap_attack/HeapAttackIT.java @@ -5,7 +5,7 @@ * 2.0. */ -package org.elasticsearch.xpack.esql.qa.single_node; +package org.elasticsearch.xpack.esql.qa.heap_attack; import org.apache.http.client.config.RequestConfig; import org.apache.http.util.EntityUtils; @@ -40,6 +40,7 @@ import static org.elasticsearch.test.MapMatcher.matchesMap; import static org.hamcrest.Matchers.any; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.hasSize; /** @@ -472,25 +473,23 @@ private void initIndex(String name, String bulk) throws IOException { Request request = new Request("POST", "/" + name + "/_refresh"); Response response = client().performRequest(request); - assertThat( - EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8), - equalTo("{\"_shards\":{\"total\":2,\"successful\":1,\"failed\":0}}") - ); + assertWriteResponse(response); request = new Request("POST", "/" + name + "/_forcemerge"); request.addParameter("max_num_segments", "1"); response = client().performRequest(request); - assertThat( - EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8), - equalTo("{\"_shards\":{\"total\":2,\"successful\":1,\"failed\":0}}") - ); + assertWriteResponse(response); request = new Request("POST", "/" + name + "/_refresh"); response = client().performRequest(request); - assertThat( - EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8), - equalTo("{\"_shards\":{\"total\":2,\"successful\":1,\"failed\":0}}") - ); + assertWriteResponse(response); + } + + @SuppressWarnings("unchecked") + private static void assertWriteResponse(Response response) throws IOException { + Map shards = (Map) entityAsMap(response).get("_shards"); + assertThat((int) shards.get("successful"), greaterThanOrEqualTo(1)); + assertThat(shards.get("failed"), equalTo(0)); } @Before diff --git a/x-pack/plugin/esql/qa/server/multi-node/build.gradle b/x-pack/plugin/esql/qa/server/multi-node/build.gradle index 1b62fdea2671c..300ed4df92bc2 100644 --- a/x-pack/plugin/esql/qa/server/multi-node/build.gradle +++ b/x-pack/plugin/esql/qa/server/multi-node/build.gradle @@ -6,7 +6,7 @@ dependencies { restResources { restApi { - include '_common', 'bulk', 'indices', 'esql', 'xpack', 'enrich' + include '_common', 'bulk', 'indices', 'esql', 'xpack' } }