Skip to content

Commit 68905df

Browse files
authored
Add mechanism to initialize YAML tests against a subset of test cases (#95095) (#95097)
This commit adds the ability to initialize YAML rest test suites against a subset of available test cases. Previously, the only way to do this is via the `tests.rest.suite` system property, but that can only be set at the test _task_ level. Configuring this at the test _class_ level means that we can support having multiple test suite classes that execute subsets of tests within a project. That allows for things like parallelization, or having different test cluster setups for different YAML tests within the same project. For example: ```java @ParametersFactory public static Iterable<Object[]> parameters() throws Exception { return ESClientYamlSuiteTestCase.createParameters(new String[] { "analysis-common", "indices.analyze" }); } ``` The above example would mean that only tests in the `analysis-common` and `indices.analyze` directories would be included in this suite. cc @jdconrad Closes #95089
1 parent f00bf45 commit 68905df

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

TESTING.asciidoc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,15 @@ A specific test case can be run with the following command:
352352
-Dtests.method="test {p0=cat.segments/10_basic/Help}"
353353
---------------------------------------------------------------------------
354354

355+
You can run a group of YAML test by using wildcards:
356+
357+
---------------------------------------------------------------------------
358+
./gradlew :rest-api-spec:yamlRestTest \
359+
--tests "org.elasticsearch.test.rest.ClientYamlTestSuiteIT.test {yaml=index/*/*}"
360+
---------------------------------------------------------------------------
361+
355362
The YAML REST tests support all the options provided by the randomized runner, plus the following:
356363

357-
* `tests.rest.suite`: comma separated paths of the test suites to be run
358-
(by default loaded from /rest-api-spec/test). It is possible to run only a subset
359-
of the tests providing a sub-folder or even a single yaml file (the default
360-
/rest-api-spec/test prefix is optional when files are loaded from classpath)
361-
e.g. -Dtests.rest.suite=index,get,create/10_with_id
362364
* `tests.rest.blacklist`: comma separated globs that identify tests that are
363365
blacklisted and need to be skipped
364366
e.g. -Dtests.rest.blacklist=index/*/Index document,get/10_basic/*

test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,32 @@ public static Iterable<Object[]> createParameters() throws Exception {
205205
* Create parameters for this parameterized test.
206206
*/
207207
public static Iterable<Object[]> createParameters(NamedXContentRegistry executeableSectionRegistry) throws Exception {
208-
String[] paths = resolvePathsProperty(REST_TESTS_SUITE, ""); // default to all tests under the test root
208+
return createParameters(executeableSectionRegistry, null);
209+
}
210+
211+
/**
212+
* Create parameters for this parameterized test.
213+
*/
214+
public static Iterable<Object[]> createParameters(String[] testPaths) throws Exception {
215+
return createParameters(ExecutableSection.XCONTENT_REGISTRY, testPaths);
216+
}
217+
218+
/**
219+
* Create parameters for this parameterized test.
220+
*
221+
* @param executeableSectionRegistry registry of executable sections
222+
* @param testPaths list of paths to explicitly search for tests. If <code>null</code> then include all tests in root path.
223+
* @return list of test candidates.
224+
* @throws Exception
225+
*/
226+
public static Iterable<Object[]> createParameters(NamedXContentRegistry executeableSectionRegistry, String[] testPaths)
227+
throws Exception {
228+
if (testPaths != null && System.getProperty(REST_TESTS_SUITE) != null) {
229+
throw new IllegalArgumentException("The '" + REST_TESTS_SUITE + "' system property is not supported with explicit test paths.");
230+
}
231+
232+
// default to all tests under the test root
233+
String[] paths = testPaths == null ? resolvePathsProperty(REST_TESTS_SUITE, "") : testPaths;
209234
Map<String, Set<Path>> yamlSuites = loadSuites(paths);
210235
List<ClientYamlTestSuite> suites = new ArrayList<>();
211236
IllegalArgumentException validationException = null;
@@ -268,7 +293,7 @@ static Map<String, Set<Path>> loadSuites(String... paths) throws Exception {
268293
});
269294
} else {
270295
path = root.resolve(strPath + ".yml");
271-
assert Files.exists(path);
296+
assert Files.exists(path) : "Path " + path + " does not exist in YAML test root";
272297
addSuite(root, path, files);
273298
}
274299
}

0 commit comments

Comments
 (0)