Skip to content

Commit bcf1bd4

Browse files
authored
Ensure Fleet REST yaml tests work in serverless (#115869)
Use new gradle plugin for the yaml tests so they can be executed in serverless CI as well. Relates ES-8275
1 parent d34c563 commit bcf1bd4

File tree

5 files changed

+57
-15
lines changed

5 files changed

+57
-15
lines changed

server/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ public SearchRequestBuilder setWaitForCheckpoints(Map<String, long[]> waitForChe
130130
return this;
131131
}
132132

133+
/**
134+
* Set the timeout for the {@link #setWaitForCheckpoints(Map)} request.
135+
*/
136+
public SearchRequestBuilder setWaitForCheckpointsTimeout(final TimeValue waitForCheckpointsTimeout) {
137+
request.setWaitForCheckpointsTimeout(waitForCheckpointsTimeout);
138+
return this;
139+
}
140+
133141
/**
134142
* Specifies what type of requested indices to ignore and wildcard indices expressions.
135143
* <p>
Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
1-
apply plugin: 'elasticsearch.legacy-yaml-rest-test'
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
27

3-
dependencies {
4-
yamlRestTestImplementation(testArtifact(project(xpackModule('core'))))
5-
}
8+
import org.elasticsearch.gradle.internal.info.BuildParams
9+
10+
apply plugin: 'elasticsearch.internal-yaml-rest-test'
11+
apply plugin: 'elasticsearch.yaml-rest-compat-test'
12+
apply plugin: 'elasticsearch.internal-test-artifact'
613

714
restResources {
815
restApi {
916
include '_common', 'bulk', 'cluster', 'nodes', 'indices', 'index', 'xpack', 'security', 'fleet'
1017
}
1118
}
1219

13-
testClusters.configureEach {
14-
testDistribution = 'DEFAULT'
15-
setting 'xpack.security.enabled', 'true'
16-
setting 'xpack.license.self_generated.type', 'trial'
17-
extraConfigFile 'roles.yml', file('roles.yml')
18-
user username: 'elastic_admin', password: 'admin-password'
19-
user username: 'fleet_unprivileged_secrets', password: 'password', role: 'unprivileged_secrets'
20+
artifacts {
21+
restXpackTests(new File(projectDir, "src/yamlRestTest/resources/rest-api-spec/test"))
22+
}
23+
24+
tasks.named('yamlRestTest') {
25+
usesDefaultDistribution()
26+
}
27+
tasks.named('yamlRestCompatTest') {
28+
usesDefaultDistribution()
29+
}
30+
if (BuildParams.inFipsJvm){
31+
// This test cluster is using a BASIC license and FIPS 140 mode is not supported in BASIC
32+
tasks.named("yamlRestTest").configure{enabled = false }
2033
}

x-pack/plugin/fleet/qa/rest/src/yamlRestTest/java/org/elasticsearch/xpack/fleet/FleetRestIT.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,43 @@
1212
import org.elasticsearch.common.settings.SecureString;
1313
import org.elasticsearch.common.settings.Settings;
1414
import org.elasticsearch.common.util.concurrent.ThreadContext;
15+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
16+
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
17+
import org.elasticsearch.test.cluster.util.resource.Resource;
1518
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
1619
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
20+
import org.junit.ClassRule;
1721

1822
public class FleetRestIT extends ESClientYamlSuiteTestCase {
1923

2024
public FleetRestIT(final ClientYamlTestCandidate testCandidate) {
2125
super(testCandidate);
2226
}
2327

28+
@ClassRule
29+
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
30+
.distribution(DistributionType.DEFAULT)
31+
.setting("xpack.license.self_generated.type", "basic")
32+
.setting("xpack.security.enabled", "true")
33+
.rolesFile(Resource.fromClasspath("roles.yml"))
34+
.user("elastic_admin", "admin-password", "superuser", true)
35+
.user("fleet_unprivileged_secrets", "password", "unprivileged_secrets", true)
36+
.build();
37+
38+
@Override
39+
protected String getTestRestCluster() {
40+
return cluster.getHttpAddresses();
41+
}
42+
2443
@Override
2544
protected Settings restClientSettings() {
26-
String authentication = basicAuthHeaderValue("elastic_admin", new SecureString("admin-password".toCharArray()));
27-
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", authentication).build();
45+
String token = basicAuthHeaderValue("elastic_admin", new SecureString("admin-password".toCharArray()));
46+
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
2847
}
2948

3049
@ParametersFactory
3150
public static Iterable<Object[]> parameters() throws Exception {
3251
return ESClientYamlSuiteTestCase.createParameters();
3352
}
53+
3454
}

x-pack/plugin/fleet/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/fleet/20_wait_for_checkpoints.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ setup:
105105
index: "test-after-refresh"
106106
allow_partial_search_results: false
107107
wait_for_checkpoints: 2
108+
wait_for_checkpoints_timeout: 1m
108109
body: { query: { match_all: {} } }
109110

110111
---
@@ -115,7 +116,7 @@ setup:
115116
body:
116117
- { "allow_partial_search_results": false, wait_for_checkpoints: 1 }
117118
- { query: { match_all: { } } }
118-
- { "allow_partial_search_results": false, wait_for_checkpoints: 2 }
119+
- { "allow_partial_search_results": false, wait_for_checkpoints: 2, wait_for_checkpoints_timeout: 1m }
119120
- { query: { match_all: { } } }
120121

121122
- match: { responses.0._shards.successful: 1 }
@@ -128,7 +129,7 @@ setup:
128129
- {query: { match_all: {} } }
129130
- { "index": "test-alias", "allow_partial_search_results": false, wait_for_checkpoints: 1 }
130131
- { query: { match_all: { } } }
131-
- {"index": "test-refresh-disabled", "allow_partial_search_results": false, wait_for_checkpoints: 2}
132+
- { "index": "test-refresh-disabled", "allow_partial_search_results": false, wait_for_checkpoints: 2, wait_for_checkpoints_timeout: 1m }
132133
- {query: { match_all: {} } }
133134

134135
- match: { responses.0._shards.successful: 1 }

0 commit comments

Comments
 (0)