Skip to content

Commit 52f36f2

Browse files
committed
Skip spec tests when test cluster broken
1 parent 1004196 commit 52f36f2

File tree

2 files changed

+20
-19
lines changed
  • x-pack/plugin/esql/qa/server

2 files changed

+20
-19
lines changed

x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/EsqlSpecIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ protected boolean supportsSourceFieldMapping() {
5353

5454
@Before
5555
public void configureChunks() throws IOException {
56+
assumeTrue("test clusters were broken", testClustersOk);
5657
boolean smallChunks = randomBoolean();
5758
Request request = new Request("PUT", "/_cluster/settings");
5859
XContentBuilder builder = JsonXContent.contentBuilder().startObject().startObject("persistent");

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/EsqlSpecTestCase.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.apache.lucene.tests.util.TimeUnits;
1414
import org.elasticsearch.Version;
1515
import org.elasticsearch.client.Request;
16-
import org.elasticsearch.client.ResponseException;
1716
import org.elasticsearch.client.RestClient;
1817
import org.elasticsearch.common.xcontent.XContentHelper;
1918
import org.elasticsearch.features.NodeFeature;
@@ -36,7 +35,6 @@
3635
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.RequestObjectBuilder;
3736
import org.elasticsearch.xpack.esql.telemetry.TookMetrics;
3837
import org.junit.After;
39-
import org.junit.AfterClass;
4038
import org.junit.Before;
4139
import org.junit.Rule;
4240

@@ -69,7 +67,6 @@
6967
import static org.elasticsearch.xpack.esql.CsvTestUtils.isEnabled;
7068
import static org.elasticsearch.xpack.esql.CsvTestUtils.loadCsvSpecValues;
7169
import static org.elasticsearch.xpack.esql.CsvTestsDataLoader.createInferenceEndpoints;
72-
import static org.elasticsearch.xpack.esql.CsvTestsDataLoader.deleteInferenceEndpoints;
7370
import static org.elasticsearch.xpack.esql.CsvTestsDataLoader.loadDataSetIntoEs;
7471
import static org.elasticsearch.xpack.esql.EsqlTestUtils.classpathResources;
7572
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.COMPLETION;
@@ -122,9 +119,11 @@ protected EsqlSpecTestCase(
122119
}
123120

124121
private static boolean dataLoaded = false;
122+
protected static boolean testClustersOk = true;
125123

126124
@Before
127125
public void setup() throws IOException {
126+
assumeTrue("test clusters were broken", testClustersOk);
128127
boolean supportsLookup = supportsIndexModeLookup();
129128
boolean supportsSourceMapping = supportsSourceFieldMapping();
130129
boolean supportsInferenceTestService = supportsInferenceTestService();
@@ -138,21 +137,6 @@ public void setup() throws IOException {
138137
}
139138
}
140139

141-
@AfterClass
142-
public static void wipeTestData() throws IOException {
143-
try {
144-
dataLoaded = false;
145-
adminClient().performRequest(new Request("DELETE", "/*"));
146-
} catch (ResponseException e) {
147-
// 404 here just means we had no indexes
148-
if (e.getResponse().getStatusLine().getStatusCode() != 404) {
149-
throw e;
150-
}
151-
}
152-
153-
deleteInferenceEndpoints(adminClient());
154-
}
155-
156140
public boolean logResults() {
157141
return false;
158142
}
@@ -162,11 +146,25 @@ public final void test() throws Throwable {
162146
shouldSkipTest(testName);
163147
doTest();
164148
} catch (Exception e) {
149+
ensureTestClustersAreOk(e);
165150
throw reworkException(e);
166151
}
167152
}
168153

154+
protected void ensureTestClustersAreOk(Exception failure) {
155+
try {
156+
ensureHealth(client(), "", (request) -> {
157+
request.addParameter("wait_for_status", "yellow");
158+
request.addParameter("level", "shards");
159+
});
160+
} catch (Exception inner) {
161+
testClustersOk = false;
162+
failure.addSuppressed(inner);
163+
}
164+
}
165+
169166
protected void shouldSkipTest(String testName) throws IOException {
167+
assumeTrue("test clusters were broken", testClustersOk);
170168
if (requiresInferenceEndpoint()) {
171169
assumeTrue("Inference test service needs to be supported", supportsInferenceTestService());
172170
}
@@ -374,7 +372,9 @@ protected boolean preserveClusterUponCompletion() {
374372

375373
@After
376374
public void assertRequestBreakerEmptyAfterTests() throws Exception {
377-
assertRequestBreakerEmpty();
375+
if (testClustersOk) {
376+
assertRequestBreakerEmpty();
377+
}
378378
}
379379

380380
public static void assertRequestBreakerEmpty() throws Exception {

0 commit comments

Comments
 (0)