From 34cdd09571a97f954f2ca150389559921d1d889d Mon Sep 17 00:00:00 2001 From: itsCodeTide Date: Wed, 14 Oct 2026 23:20:28 +0530 Subject: [PATCH] ci(elasticsearch): split slow module tests --- .github/workflows/ci.yml | 17 +++++++- .../ElasticsearchContainerTest.java | 42 ++++++------------- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0ced008ba4..6fd46208c4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -97,7 +97,22 @@ jobs: READ_ONLY_REMOTE_GRADLE_CACHE: true run: | set -o pipefail - TASKS=$(./gradlew --no-daemon --parallel -q testMatrix | jq 'del(.[] | select(. == ":testcontainers:check" or startswith(":docs:")))' --compact-output) + # Keep Elasticsearch checks and its two slow test classes in separate matrix jobs. + TASKS=$(./gradlew --no-daemon --parallel -q testMatrix | jq ' + del(.[] | select(. == ":testcontainers:check" or startswith(":docs:"))) + | map( + if . == ":testcontainers-elasticsearch:check" then + [ + ":testcontainers-elasticsearch:check -x :testcontainers-elasticsearch:test", + ":testcontainers-elasticsearch:test --tests org.testcontainers.elasticsearch.ElasticsearchContainerTest", + ":testcontainers-elasticsearch:test --tests org.testcontainers.elasticsearch.KibanaContainerTest" + ] + else + [.] + end + ) + | flatten + ' --compact-output) echo $TASKS echo "matrix={\"gradle_args\":$TASKS}" >> $GITHUB_OUTPUT check: diff --git a/modules/elasticsearch/src/test/java/org/testcontainers/elasticsearch/ElasticsearchContainerTest.java b/modules/elasticsearch/src/test/java/org/testcontainers/elasticsearch/ElasticsearchContainerTest.java index ca23e99f3d5..1e7d954200a 100644 --- a/modules/elasticsearch/src/test/java/org/testcontainers/elasticsearch/ElasticsearchContainerTest.java +++ b/modules/elasticsearch/src/test/java/org/testcontainers/elasticsearch/ElasticsearchContainerTest.java @@ -106,7 +106,7 @@ public void stopRestClient() throws IOException { // Latest (default coverage) @Test - void latestStartsWithTlsAndPassword() throws IOException { + void latestStartsWithTlsAndPassword() throws Exception { // httpClientLatest { // Create the elasticsearch container. try (ElasticsearchContainer container = new ElasticsearchContainer(ELASTICSEARCH_IMAGE_LATEST)) { @@ -134,7 +134,14 @@ void latestStartsWithTlsAndPassword() throws IOException { Response response = client.performRequest(new Request("GET", "/_cluster/health")); // }} assertThat(response.getStatusLine().getStatusCode()).as("cluster health is available").isEqualTo(200); - assertThat(EntityUtils.toString(response.getEntity())).contains("cluster_name"); + String clusterHealth = EntityUtils.toString(response.getEntity()); + assertThat(clusterHealth).contains("cluster_name"); + assertThat(clusterHealth) + .as("Cluster health status should be at least yellow after container start") + .satisfiesAnyOf( + body -> assertThat(body).contains("\"status\":\"yellow\""), + body -> assertThat(body).contains("\"status\":\"green\"") + ); assertThat(container.getHttpScheme()).as("HTTP API uses HTTPS by default").isEqualTo("https"); response = client.performRequest(new Request("GET", "/")); @@ -149,6 +156,9 @@ void latestStartsWithTlsAndPassword() throws IOException { .as("Elastic licensed features are available") .contains("monitoring"); + // Default is 2g, see https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html + assertElasticsearchContainerHasHeapSize(container, 2_147_483_648L); + assertThat(catchThrowable(() -> getAnonymousClient(container).performRequest(new Request("GET", "/")))) .as("anonymous requests are rejected") .isInstanceOf(ResponseException.class); @@ -232,23 +242,6 @@ void latestHonorsCustomHttpsWaitStrategy() throws Exception { } } - @Test - void clusterHealthIsAtLeastYellowAfterStart() throws IOException { - try (ElasticsearchContainer container = new ElasticsearchContainer(ELASTICSEARCH_IMAGE_LATEST)) { - container.start(); - - Response response = getClient(container).performRequest(new Request("GET", "/_cluster/health")); - assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200); - String body = EntityUtils.toString(response.getEntity()); - assertThat(body) - .as("Cluster health status should be at least yellow after container start") - .satisfiesAnyOf( - b -> assertThat(b).contains("\"status\":\"yellow\""), - b -> assertThat(b).contains("\"status\":\"green\"") - ); - } - } - @Test void latestWorksWithDockerHubImage() throws Exception { try ( @@ -262,17 +255,6 @@ void latestWorksWithDockerHubImage() throws Exception { } } - @Test - void latestDefaultHeapIsTwoGb() throws Exception { - // Default is 2g, see https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html - long defaultHeapSize = 2_147_483_648L; - - try (ElasticsearchContainer container = new ElasticsearchContainer(ELASTICSEARCH_IMAGE_LATEST)) { - container.start(); - assertElasticsearchContainerHasHeapSize(container, defaultHeapSize); - } - } - @Test void latestHeapCanBeSetViaEnv() throws Exception { String customHeapSize = "1500m";