Skip to content

Commit 77c1084

Browse files
committed
Backported test for the headers fix
1 parent 09ad351 commit 77c1084

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

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

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,10 @@ public static Map<String, Object> runEsqlSync(RequestObjectBuilder requestObject
12821282
HttpEntity entity = response.getEntity();
12831283
Map<String, Object> json = entityToMap(entity, requestObject.contentType());
12841284

1285+
var supportsAsyncHeadersFix = hasCapabilities(adminClient(), List.of("async_query_status_headers_fix"));
1286+
if (supportsAsyncHeadersFix) {
1287+
assertNoAsyncHeaders(response);
1288+
}
12851289
assertWarnings(response, assertWarnings);
12861290

12871291
return json;
@@ -1312,17 +1316,18 @@ public static Map<String, Object> runEsqlAsync(
13121316
checkKeepOnCompletion(requestObject, json, keepOnCompletion);
13131317
String id = (String) json.get("id");
13141318

1315-
var supportsAsyncHeaders = hasCapabilities(adminClient(), List.of("async_query_status_headers"));
1319+
var supportsAsyncHeaders = hasCapabilities(adminClient(), List.of("async_query_status_headers_fix"));
13161320
var supportsSuggestedCast = hasCapabilities(adminClient(), List.of("suggested_cast"));
13171321

1322+
// Check headers on initial query call
1323+
if (supportsAsyncHeaders) {
1324+
assertAsyncHeaders(response, id, (boolean) json.get("is_running"));
1325+
}
1326+
13181327
if (id == null) {
13191328
// no id returned from an async call, must have completed immediately and without keep_on_completion
13201329
assertThat(requestObject.keepOnCompletion(), either(nullValue()).or(is(false)));
13211330
assertThat((boolean) json.get("is_running"), is(false));
1322-
if (supportsAsyncHeaders) {
1323-
assertThat(response.getHeader("X-Elasticsearch-Async-Id"), nullValue());
1324-
assertThat(response.getHeader("X-Elasticsearch-Async-Is-Running"), is("?0"));
1325-
}
13261331
assertWarnings(response, assertWarnings);
13271332
json.remove("is_running"); // remove this to not mess up later map assertions
13281333
return Collections.unmodifiableMap(json);
@@ -1343,11 +1348,6 @@ public static Map<String, Object> runEsqlAsync(
13431348
assertThat(json.get("pages"), nullValue());
13441349
}
13451350

1346-
if (supportsAsyncHeaders) {
1347-
assertThat(response.getHeader("X-Elasticsearch-Async-Id"), is(id));
1348-
assertThat(response.getHeader("X-Elasticsearch-Async-Is-Running"), is(isRunning ? "?1" : "?0"));
1349-
}
1350-
13511351
// issue a second request to "async get" the results
13521352
Request getRequest = prepareAsyncGetRequest(id);
13531353
getRequest.setOptions(request.getOptions());
@@ -1357,6 +1357,11 @@ public static Map<String, Object> runEsqlAsync(
13571357

13581358
var result = entityToMap(entity, requestObject.contentType());
13591359

1360+
// Check headers on get call
1361+
if (supportsAsyncHeaders) {
1362+
assertAsyncHeaders(response, id, (boolean) result.get("is_running"));
1363+
}
1364+
13601365
// assert initial contents, if any, are the same as async get contents
13611366
if (initialColumns != null) {
13621367
if (supportsSuggestedCast == false) {
@@ -1850,6 +1855,16 @@ private static void createIndex(String indexName, boolean lookupMode, String map
18501855
assertEquals(200, client().performRequest(request).getStatusLine().getStatusCode());
18511856
}
18521857

1858+
private static void assertAsyncHeaders(Response response, @Nullable String asyncId, boolean isRunning) {
1859+
assertThat(response.getHeader("X-Elasticsearch-Async-Id"), asyncId == null ? nullValue() : equalTo(asyncId));
1860+
assertThat(response.getHeader("X-Elasticsearch-Async-Is-Running"), isRunning ? is("?1") : is("?0"));
1861+
}
1862+
1863+
private static void assertNoAsyncHeaders(Response response) {
1864+
assertThat(response.getHeader("X-Elasticsearch-Async-Id"), nullValue());
1865+
assertThat(response.getHeader("X-Elasticsearch-Async-Is-Running"), nullValue());
1866+
}
1867+
18531868
public static RequestObjectBuilder requestObjectBuilder() throws IOException {
18541869
return new RequestObjectBuilder();
18551870
}

0 commit comments

Comments
 (0)