Skip to content

Commit

Permalink
Updates to TESTING.asciidoc for REST testing (elastic#52862)
Browse files Browse the repository at this point in the history
Update documentation for:
* restResources config (related elastic#52114)
* call out YAML vs. Java based Rest tests
* update example to use newer syntax 
* update example to target a test that is not skipped 
* provide example for bwcRest test (related elastic#52383)
  • Loading branch information
jakelandis committed Feb 27, 2020
1 parent 5e1ea07 commit 95f8c77
Showing 1 changed file with 42 additions and 18 deletions.
60 changes: 42 additions & 18 deletions TESTING.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -273,34 +273,49 @@ test fixtures. If it's not present those checks will be skipped automatically.

== Testing the REST layer

The available integration tests make use of the java API to communicate with
the elasticsearch nodes, using the internal binary transport (port 9300 by
default).
The REST layer is tested through specific tests that are shared between all
the elasticsearch official clients and consist of YAML files that describe the
The REST layer is tested through specific tests that are executed against
a cluster that is configured and initialized via Gradle. The tests
themselves can be written in either Java or with a YAML based DSL.

YAML based REST tests should be preferred since these are shared between all
the elasticsearch official clients. The YAML based tests describe the
operations to be executed and the obtained results that need to be tested.

The YAML files support various operators defined in the link:/rest-api-spec/src/main/resources/rest-api-spec/test/README.asciidoc[rest-api-spec] and adhere to the link:/rest-api-spec/README.markdown[Elasticsearch REST API JSON specification]
The YAML tests support various operators defined in the link:/rest-api-spec/src/main/resources/rest-api-spec/test/README.asciidoc[rest-api-spec] and adhere to the link:/rest-api-spec/README.markdown[Elasticsearch REST API JSON specification]
In order to run the the YAML tests, the relevant API specification needs
to be on the test classpath. Any gradle project that has support for REST
tests will get the primary API on it's class path. However, to better support
Gradle incremental builds, it is recommended to explicitly declare which
parts of the API the tests depend upon.

For example:
---------------------------------------------------------------------------
restResources {
restApi {
includeCore '_common', 'indices', 'index', 'cluster', 'nodes', 'get', 'ingest'
}
}
---------------------------------------------------------------------------

YAML tests that include x-pack specific APIs need to explicitly declare
which APIs are required through a similar `includeXpack` configuration.

The REST tests are run automatically when executing the "./gradlew check" command. To run only the
REST tests use the following command:

---------------------------------------------------------------------------
./gradlew :distribution:archives:integ-test-zip:integTest \
-Dtests.class="org.elasticsearch.test.rest.*Yaml*IT"
./gradlew :distribution:archives:integ-test-zip:integTestRunner \
--tests "org.elasticsearch.test.rest.IntegTestZipClientYamlTestSuiteIT"
---------------------------------------------------------------------------

A specific test case can be run with
A specific test case can be run with the following command:

---------------------------------------------------------------------------
./gradlew :distribution:archives:integ-test-zip:integTest \
-Dtests.class="org.elasticsearch.test.rest.*Yaml*IT" \
-Dtests.method="test {p0=cat.shards/10_basic/Help}"
./gradlew ':distribution:archives:integ-test-zip:integTestRunner' \
--tests "org.elasticsearch.test.rest.IntegTestZipClientYamlTestSuiteIT" \
-Dtests.method="test {p0=cat.segments/10_basic/Help}"
---------------------------------------------------------------------------

`*Yaml*IT` are the executable test classes that runs all the
yaml suites available within the `rest-api-spec` folder.

The REST tests support all the options provided by the randomized runner, plus the following:

* `tests.rest[true|false]`: determines whether the REST tests need to be run (default) or not.
Expand Down Expand Up @@ -494,6 +509,14 @@ version 5.3.2 run:
./gradlew v5.3.2#bwcTest
-------------------------------------------------

Use -Dtest.class and -Dtests.method to run a specific bwcTest test.
For example to run a specific tests from the x-pack rolling upgrade from 7.7.0:
-------------------------------------------------
./gradlew :x-pack:qa:rolling-upgrade:v7.7.0#bwcTest \
-Dtests.class=org.elasticsearch.upgrades.UpgradeClusterClientYamlTestSuiteIT \
-Dtests.method="test {p0=*/40_ml_datafeed_crud/*}"
-------------------------------------------------

Tests are ran for versions that are not yet released but with which the current version will be compatible with.
These are automatically checked out and built from source.
See link:./buildSrc/src/main/java/org/elasticsearch/gradle/VersionCollection.java[VersionCollection]
Expand Down Expand Up @@ -547,8 +570,9 @@ There are multiple base classes for tests:
* **`ESIntegTestCase`**: An integration test case that creates a cluster that
might have multiple nodes.
* **`ESRestTestCase`**: An integration tests that interacts with an external
cluster via the REST API. For instance, YAML tests run via sub classes of
`ESRestTestCase`.
cluster via the REST API. This is used for Java based REST tests.
* **`ESClientYamlSuiteTestCase` **: A subclass of `ESRestTestCase` used to run
YAML based REST tests.

=== Good practices

Expand Down Expand Up @@ -678,4 +702,4 @@ please see https://esrally.readthedocs.io/en/stable/[Rally's documentation].

The Elasticsearch docs are in AsciiDoc format. You can test and build the docs
locally using the Elasticsearch documentation build process. See
https://github.com/elastic/docs.
https://github.com/elastic/docs.

0 comments on commit 95f8c77

Please sign in to comment.