mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-04-19 04:45:07 -04:00
Fix tests in TimeSeriesDataStreamsIT
(#126851)
These tests had the potential to fail when subsequent requests would hit different nodes with different versions of the cluster state. Only one of these tests failed already, but we fix the other ones proactively to avoid future failures. Fixes #126746
This commit is contained in:
parent
0d01f88f95
commit
16070a342f
3 changed files with 39 additions and 21 deletions
|
@ -387,9 +387,6 @@ tests:
|
|||
- class: org.elasticsearch.xpack.esql.action.EsqlActionIT
|
||||
method: testQueryOnEmptyDataIndex
|
||||
issue: https://github.com/elastic/elasticsearch/issues/126580
|
||||
- class: org.elasticsearch.xpack.ilm.TimeSeriesDataStreamsIT
|
||||
method: testShrinkActionInPolicyWithoutHotPhase
|
||||
issue: https://github.com/elastic/elasticsearch/issues/126746
|
||||
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
|
||||
method: test {p0=transform/transforms_start_stop/Test start/stop/start continuous transform}
|
||||
issue: https://github.com/elastic/elasticsearch/issues/126755
|
||||
|
|
|
@ -2044,12 +2044,34 @@ public abstract class ESRestTestCase extends ESTestCase {
|
|||
}
|
||||
|
||||
protected static boolean indexExists(String index) throws IOException {
|
||||
return indexExists(client(), index);
|
||||
// We use the /_cluster/health/{index} API to ensure the index exists on the master node - which means all nodes see the index.
|
||||
Request request = new Request("GET", "/_cluster/health/" + index);
|
||||
request.addParameter("timeout", "0");
|
||||
request.addParameter("level", "indices");
|
||||
try {
|
||||
final var response = client().performRequest(request);
|
||||
@SuppressWarnings("unchecked")
|
||||
final var indices = (Map<String, Object>) entityAsMap(response).get("indices");
|
||||
return indices.containsKey(index);
|
||||
} catch (ResponseException e) {
|
||||
if (e.getResponse().getStatusLine().getStatusCode() == HttpStatus.SC_REQUEST_TIMEOUT) {
|
||||
return false;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
protected static boolean indexExists(RestClient client, String index) throws IOException {
|
||||
Response response = client.performRequest(new Request("HEAD", "/" + index));
|
||||
return RestStatus.OK.getStatus() == response.getStatusLine().getStatusCode();
|
||||
protected static void awaitIndexExists(String index) throws IOException {
|
||||
awaitIndexExists(index, SAFE_AWAIT_TIMEOUT);
|
||||
}
|
||||
|
||||
protected static void awaitIndexExists(String index, TimeValue timeout) throws IOException {
|
||||
// We use the /_cluster/health/{index} API to ensure the index exists on the master node - which means all nodes see the index.
|
||||
ensureHealth(client(), index, request -> request.addParameter("timeout", timeout.toString()));
|
||||
}
|
||||
|
||||
protected static void awaitIndexDoesNotExist(String index, TimeValue timeout) throws Exception {
|
||||
assertBusy(() -> assertFalse(indexExists(index)), timeout.millis(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.elasticsearch.client.WarningFailureException;
|
|||
import org.elasticsearch.cluster.metadata.IndexMetadata;
|
||||
import org.elasticsearch.cluster.metadata.Template;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.core.TimeValue;
|
||||
import org.elasticsearch.index.engine.EngineConfig;
|
||||
import org.elasticsearch.test.rest.ESRestTestCase;
|
||||
import org.elasticsearch.xcontent.XContentType;
|
||||
|
@ -153,7 +154,7 @@ public class TimeSeriesDataStreamsIT extends ESRestTestCase {
|
|||
);
|
||||
|
||||
String shrunkenIndex = waitAndGetShrinkIndexName(client(), backingIndexName);
|
||||
assertBusy(() -> assertTrue(indexExists(shrunkenIndex)), 30, TimeUnit.SECONDS);
|
||||
awaitIndexExists(shrunkenIndex, TimeValue.timeValueSeconds(30));
|
||||
assertBusy(() -> assertThat(getStepKeyForIndex(client(), shrunkenIndex), equalTo(PhaseCompleteStep.finalStep("warm").getKey())));
|
||||
assertBusy(() -> assertThat("the original index must've been deleted", indexExists(backingIndexName), is(false)));
|
||||
}
|
||||
|
@ -182,8 +183,8 @@ public class TimeSeriesDataStreamsIT extends ESRestTestCase {
|
|||
// Manual rollover the original index such that it's not the write index in the data stream anymore
|
||||
rolloverMaxOneDocCondition(client(), dataStream);
|
||||
|
||||
assertBusy(() -> assertThat(indexExists(restoredIndexName), is(true)));
|
||||
assertBusy(() -> assertFalse(indexExists(backingIndexName)), 60, TimeUnit.SECONDS);
|
||||
awaitIndexExists(restoredIndexName);
|
||||
awaitIndexDoesNotExist(backingIndexName, TimeValue.timeValueSeconds(60));
|
||||
assertBusy(
|
||||
() -> assertThat(explainIndex(client(), restoredIndexName).get("step"), is(PhaseCompleteStep.NAME)),
|
||||
30,
|
||||
|
@ -211,15 +212,13 @@ public class TimeSeriesDataStreamsIT extends ESRestTestCase {
|
|||
// Manual rollover the original index such that it's not the write index in the data stream anymore
|
||||
rolloverMaxOneDocCondition(client(), dataStream);
|
||||
|
||||
assertBusy(
|
||||
() -> assertThat(explainIndex(client(), backingIndexName).get("step"), is(PhaseCompleteStep.NAME)),
|
||||
30,
|
||||
TimeUnit.SECONDS
|
||||
);
|
||||
assertThat(
|
||||
getOnlyIndexSettings(client(), backingIndexName).get(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey()),
|
||||
equalTo("true")
|
||||
);
|
||||
assertBusy(() -> {
|
||||
assertThat(explainIndex(client(), backingIndexName).get("step"), is(PhaseCompleteStep.NAME));
|
||||
assertThat(
|
||||
getOnlyIndexSettings(client(), backingIndexName).get(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey()),
|
||||
equalTo("true")
|
||||
);
|
||||
}, 30, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public void testFreezeAction() throws Exception {
|
||||
|
@ -243,10 +242,10 @@ public class TimeSeriesDataStreamsIT extends ESRestTestCase {
|
|||
containsString("The freeze action in ILM is deprecated and will be removed in a future version")
|
||||
);
|
||||
}
|
||||
Map<String, Object> settings = getOnlyIndexSettings(client(), backingIndexName);
|
||||
assertNull(settings.get("index.frozen"));
|
||||
}, 30, TimeUnit.SECONDS);
|
||||
|
||||
Map<String, Object> settings = getOnlyIndexSettings(client(), backingIndexName);
|
||||
assertNull(settings.get("index.frozen"));
|
||||
}
|
||||
|
||||
public void checkForceMergeAction(String codec) throws Exception {
|
||||
|
|
Loading…
Add table
Reference in a new issue