Skip to content

Create plugin for yamlTest task #56841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Jul 6, 2020
Merged

Conversation

jakelandis
Copy link
Contributor

@jakelandis jakelandis commented May 15, 2020

This commit creates a new Gradle plugin to provide a separate task name
and source set for running YAML based REST tests. The only project
converted to use the new plugin in this PR is distribution/archives/integ-test-zip.
For which the testing has been moved to :rest-api-spec since it makes the most
sense and it avoids a small but awkward change to the distribution plugin.

The remaining cases in modules, plugins, and x-pack will be handled in followups.

This plugin is distinctly different from the plugin introduced in #55896 since
the YAML REST tests are intended to be black box tests over HTTP. As such they
should not (by default) have access to the classpath for that which they are testing.

The YAML based REST tests will be moved to separate source sets (yamlRestTest).
The which source is the target for the test resources is dependent on if this
new plugin is applied. If it is not applied, it will default to the test source
set.

Further, this introduces a breaking change for plugin developers that
use the YAML testing framework. They will now need to either use the new source set
and matching task, or configure the rest resources to use the old "test" source set that
matches the old integTest task. (The former should be preferred).

As part of this change (which is also breaking for plugin developers) the
rest resources plugin has been removed from the build plugin and now requires
either explicit application or application via the new YAML REST test plugin.

Plugin developers should be able to fix the breaking changes to the YAML tests
by adding apply plugin: 'elasticsearch.yaml-rest-test' and moving the YAML tests
under a yamlRestTest folder (instead of test)

@jakelandis jakelandis changed the title Yaml test part1 Create plugin for yamlTest task May 15, 2020
@jakelandis
Copy link
Contributor Author

@elasticmachine test this please

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (:Core/Infra/Build)

@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label May 15, 2020
@jakelandis jakelandis requested review from mark-vieira and rjernst May 15, 2020 21:25
@jakelandis jakelandis marked this pull request as ready for review May 15, 2020 21:25
@mark-vieira
Copy link
Contributor

it is still desirable for plugin development to support
YAML based REST tests from the standard Java based directories.

Why? The main motivator here is to make these things very explicit. The directory this stuff goes in dictates the kind of test. Supporting such a "hybrid" approach conflicts with that goal. In what scenario would a developer require these test live in the unit testing source set instead of the YAML test one?

@@ -36,6 +36,8 @@
private static final String TESTS_CLUSTER = "tests.cluster";
private static final String TESTS_CLUSTER_NAME = "tests.clustername";

// TODO: refactor this so that work is not done in constructor and find usages and register them, not create them
// See: https://docs.gradle.org/current/userguide/task_configuration_avoidance.html
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, there's an open issue for this. Perhaps we can link it here.

#47804

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -109,7 +111,8 @@ public FileTree getInputDir() {

@OutputDirectory
public File getOutputDir() {
return new File(getTestSourceSet().getOutput().getResourcesDir(), REST_API_PREFIX);
assert Util.getTestSourceSet(getProject()).isPresent();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use orElseThrow() here and supply an exception with an appropriate message.

Copy link
Contributor Author

@jakelandis jakelandis Jun 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a message to the assert
EDIT: after testing .. the assert did not fire as expected, so removed it in favor of orElseThrow

* @param project The project to look for test Java resources.
* @return An Optional that contains the Java test SourceSet if it exists.
*/
public static Optional<SourceSet> getTestSourceSet(Project project) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in my comment, I don't think we need to support this case. We should require that all YAML tests live in the appropriate source set. This awkward conditional stuff is a great example of why.

Also, what happens if a project has both tests types? Which source set should this method return? As part of splitting these types of tests up there is no longer a canonical "test source set", as any given project might (and likely will) have several.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed in person. Since this is used primarily for copy around of REST resources, I will remove this method in favor of having the REST resources be explicit about which source set they will use dependent on the application (or not) of the new YAML test task.

Also, this PR updated to use this with test conventions task, but that isn't needed for custom test source sets.

There will still be a todo to circle back around and remove the conditional aspect of which test source set is used for copying around REST resources, but that can only be done after all existing usages of the java test source set have been addressed. This includes ensuring that the clients teams won't break on moving tests around, as well all internal usages where YAML tests can live in the java test source set. While plugin developers may be non-passively impacted by requiring the new YAML plugin, the migration path is pretty simple and would only impact those that leverage YAML testing (suspected to be very few).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done ... will add summary to main comment.

@Override
public void apply(Project project) {

if (project.getPluginManager().hasPlugin("elasticsearch.build") == false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't have to do this. Let's just apply the correct plugin here, which is going to be the ElasticsearchJavaPlugin most likely. We don't want to have users have to worry about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

yamlTestTask.setDescription("Runs the YAML based REST tests against an external cluster");

// setup task dependency
project.getDependencies().add(SOURCE_SET_NAME + "Compile", project.project(":test:framework"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now we need to check if BuildParams.isInternal here and use an artifact dependency if not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

runner.setTestClassesDirs(yamlTestSourceSet.getOutput().getClassesDirs());
runner.setClasspath(yamlTestSourceSet.getRuntimeClasspath());

// if this a module or plugin, it may have an associated zip file with it's contents, add that to the test cluster
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the PluginBuildPlugin be doing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow ?
This section of code is the magic that adds only the required modules/plugins to the test clusters for the OSS YAML tests. This is mostly a copy for how it currently works.

GradleUtils.setupIdeForTestSourceSet(project, yamlTestSourceSet);

// run test tasks first if they exist since they are presumably faster and less resources intensive
Task testTask = project.getTasks().findByName("test");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this. I don't think it should go here, plus using findByName is going to eagerly realize the task.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated it to be inline with #57016

}

// validation of the rest specification is wired to precommit, so ensure that runs first
yamlTestTask.mustRunAfter(project.getTasks().getByName("precommit"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's creating the precommit task in this scenario? Is it some other plugin we're applying?

Copy link
Member

@rjernst rjernst May 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note #56926 will make this easier, you shouldn't have to worry about it. Currently that we already have:

project.getTasks().named(JavaPlugin.TEST_TASK_NAME).configure(t -> t.mustRunAfter(precommit));

But we can change that to all Test tasks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this line since #56926 addressed all Test tasks

@jakelandis
Copy link
Contributor Author

Why? The main motivator here is to make these things very explicit. The directory this stuff goes in dictates the kind of test. Supporting such a "hybrid" approach conflicts with that goal. In what scenario would a developer require these test live in the unit testing source set instead of the YAML test one?

Two reasons:

  • To prevent breaking plugin developers that use the YAML test framework (specifically the copy REST artifacts parts need to continue to support the original locations)
  • To support our code base until all of the changes are implemented.

For both cases I can follow up with removal for 8.0 only.

@rjernst
Copy link
Member

rjernst commented May 18, 2020

To prevent breaking plugin developers that use the YAML test framework

I don't think we need to wait until 8.0. We have been very explicit to plugin developers that there can be breaks in minor versions.

jakelandis added a commit to jakelandis/elasticsearch that referenced this pull request May 20, 2020
Some standalone projects such as :distribution:archives:integ-test-zip have tests
but are not intended to ever create a jar. Applying the new ElasticsearchJavaPlugin
in favor over the elder "Standalone*Plugin" or BuildPlugin can result in these non-jar
projects erroring due to the lack of the license or notice file.

To avoid creating more permutations of ElasticsearchJavaPlugin
(i.e. ElasticsearchJavaPluginWithoutJar), the conuming project should be able disable
the jar task (e.g. `jar.enabled = false`) and the license checks should be skipped as
well as the javadoc and sources jars.

related: elastic#56841
jakelandis added a commit that referenced this pull request Jul 28, 2020
) (#60026)

Introduce a javaRestTest source set and task to compliment the yamlRestTest.
javaRestTest differs such that the code is sourced from Java and may have
different dependencies and setup requirements for the test clusters. This also
allows the tests to run in parallel in different cluster instances to prevent any
cross test contamination between the two types of tests.

Included in this PR is all :modules no longer use the integTest task. The tests
are now driven by test, yamlRestTest, javaRestTest, and internalClusterTest.
Since only :modules (and :rest-api-spec) have been converted to yamlRestTest
we can now disable the integTest task if either yamlRestTest or javaRestTest have
been applied. Once all projects are converted, we can delete the integTest task.

related: #56841
related: #59444
jakelandis added a commit that referenced this pull request Jul 28, 2020
…nternalClusterTest (#59444)

For all OSS plugins (except repository-* and discovery-*) integTest
task is now a no-op and all of the tests are now executed via a test,
yamlRestTest, javaRestTest, or internalClusterTest.

This commit does NOT convert the discovery-* and repository-* since they
are bit more complex then the rest of tests and this PR is large enough.
Those plugins will be addressed in a future PR(s).

This commit also fixes a minor issue that did not copy the rest api
for projects that only had YAML TEST tests.

related: #56841
jakelandis added a commit to jakelandis/elasticsearch that referenced this pull request Jul 28, 2020
…nternalClusterTest (elastic#59444)

For all OSS plugins (except repository-* and discovery-*) integTest
task is now a no-op and all of the tests are now executed via a test,
yamlRestTest, javaRestTest, or internalClusterTest.

This commit does NOT convert the discovery-* and repository-* since they
are bit more complex then the rest of tests and this PR is large enough.
Those plugins will be addressed in a future PR(s).

This commit also fixes a minor issue that did not copy the rest api
for projects that only had YAML TEST tests.

related: elastic#56841
# Conflicts:
#	plugins/examples/painless-whitelist/build.gradle
#	plugins/examples/security-authorization-engine/build.gradle
jakelandis added a commit that referenced this pull request Jul 28, 2020
…alClusterTest (#60084)

For OSS plugins that begin with discovery-*, the integTest
task is now a no-op and all of the tests are now executed via a test,
yamlRestTest, javaRestTest, or internalClusterTest.

related: #56841
related: #59444
jakelandis added a commit to jakelandis/elasticsearch that referenced this pull request Jul 28, 2020
…alClusterTest (elastic#60084)

For OSS plugins that begin with discovery-*, the integTest
task is now a no-op and all of the tests are now executed via a test,
yamlRestTest, javaRestTest, or internalClusterTest.

related: elastic#56841
related: elastic#59444
jakelandis added a commit that referenced this pull request Jul 28, 2020
…nalClusterTest (#60085)

For OSS plugins that being with repository-*, integTest
task is now a no-op and all of the tests are now executed via a test,
yamlRestTest, javaRestTest, or internalClusterTest.

related: #56841
related: #59444
jakelandis added a commit to jakelandis/elasticsearch that referenced this pull request Jul 29, 2020
…nalClusterTest (elastic#60085)

For OSS plugins that being with repository-*, integTest
task is now a no-op and all of the tests are now executed via a test,
yamlRestTest, javaRestTest, or internalClusterTest.

related: elastic#56841
related: elastic#59444
jakelandis added a commit that referenced this pull request Jul 29, 2020
… internalClusterTest (#60085) (#60404)

For OSS plugins that being with repository-*, integTest
task is now a no-op and all of the tests are now executed via a test,
yamlRestTest, javaRestTest, or internalClusterTest.

related: #56841
related: #59444
jakelandis added a commit that referenced this pull request Jul 29, 2020
…internalClusterTest (#60084) (#60344)

For OSS plugins that begin with discovery-*, the integTest
task is now a no-op and all of the tests are now executed via a test,
yamlRestTest, javaRestTest, or internalClusterTest.

related: #56841
related: #59444
jakelandis added a commit that referenced this pull request Jul 29, 2020
…t or internalClusterTest (#59444) (#60343)

For all OSS plugins (except repository-* and discovery-*) integTest
task is now a no-op and all of the tests are now executed via a test,
yamlRestTest, javaRestTest, or internalClusterTest.

This commit does NOT convert the discovery-* and repository-* since they
are bit more complex then the rest of tests and this PR is large enough.
Those plugins will be addressed in a future PR(s).

This commit also fixes a minor issue that did not copy the rest api
for projects that only had YAML TEST tests.

related: #56841
jakelandis added a commit that referenced this pull request Sep 2, 2020
…est or internalClusterTest (#60630)

For 1/2 the plugins in x-pack, the integTest
task is now a no-op and all of the tests are now executed via a test,
yamlRestTest, javaRestTest, or internalClusterTest.

This includes the following projects:
async-search, autoscaling, ccr, enrich, eql, frozen-indicies,
data-streams, graph, ilm, mapper-constant-keyword, mapper-flattened, ml

A few of the more specialized qa projects within these plugins
have not been changed with this PR due to additional complexity which should
be addressed separately.

A follow up PR will address the remaining x-pack plugins (this PR is big enough as-is).

related: #61802
related: #56841
related: #59939
related: #55896
jakelandis added a commit that referenced this pull request Sep 2, 2020
…Test or internalClusterTest (#61802)

For 1/2 the plugins in x-pack, the integTest
task is now a no-op and all of the tests are now executed via a test,
yamlRestTest, javaRestTest, or internalClusterTest.

This includes the following projects:
security, spatial, stack, transform, vecotrs, voting-only-node, and watcher.

A few of the more specialized qa projects within these plugins
have not been changed with this PR due to additional complexity which should
be addressed separately. 

related: #60630
related: #56841
related: #59939
related: #55896
jakelandis added a commit to jakelandis/elasticsearch that referenced this pull request Sep 2, 2020
…est or internalClusterTest (elastic#60630)

For 1/2 the plugins in x-pack, the integTest
task is now a no-op and all of the tests are now executed via a test,
yamlRestTest, javaRestTest, or internalClusterTest.

This includes the following projects:
async-search, autoscaling, ccr, enrich, eql, frozen-indicies,
data-streams, graph, ilm, mapper-constant-keyword, mapper-flattened, ml

A few of the more specialized qa projects within these plugins
have not been changed with this PR due to additional complexity which should
be addressed separately.

A follow up PR will address the remaining x-pack plugins (this PR is big enough as-is).

related: elastic#61802
related: elastic#56841
related: elastic#59939
related: elastic#55896
# Conflicts:
#	x-pack/plugin/identity-provider/src/internalClusterTest/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderIndexTests.java
#	x-pack/plugin/ilm/qa/with-security/build.gradle
jakelandis added a commit to jakelandis/elasticsearch that referenced this pull request Sep 2, 2020
…Test or internalClusterTest (elastic#61802)

For 1/2 the plugins in x-pack, the integTest
task is now a no-op and all of the tests are now executed via a test,
yamlRestTest, javaRestTest, or internalClusterTest.

This includes the following projects:
security, spatial, stack, transform, vecotrs, voting-only-node, and watcher.

A few of the more specialized qa projects within these plugins
have not been changed with this PR due to additional complexity which should
be addressed separately.

related: elastic#60630
related: elastic#56841
related: elastic#59939
related: elastic#55896
# Conflicts:
#	x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/integration/IndexPrivilegeIntegTests.java
#	x-pack/plugin/security/src/test/java/org/elasticsearch/integration/IndexPrivilegeIntegTests.java
#	x-pack/plugin/security/src/test/java/org/elasticsearch/integration/IndexPrivilegeTests.java
#	x-pack/plugin/transform/qa/multi-node-tests/build.gradle
#	x-pack/plugin/transform/qa/single-node-tests/build.gradle
#	x-pack/plugin/watcher/build.gradle
jakelandis added a commit that referenced this pull request Sep 2, 2020
…]RestTest or internalClusterTest (#60630) (#61855)

For 1/2 the plugins in x-pack, the integTest
task is now a no-op and all of the tests are now executed via a test,
yamlRestTest, javaRestTest, or internalClusterTest.

This includes the following projects:
async-search, autoscaling, ccr, enrich, eql, frozen-indicies,
data-streams, graph, ilm, mapper-constant-keyword, mapper-flattened, ml

A few of the more specialized qa projects within these plugins
have not been changed with this PR due to additional complexity which should
be addressed separately.

A follow up PR will address the remaining x-pack plugins (this PR is big enough as-is).

related: #61802
related: #56841
related: #59939
related: #55896
jakelandis added a commit that referenced this pull request Sep 2, 2020
…a]RestTest or internalClusterTest (#61802) (#61856)

For 1/2 the plugins in x-pack, the integTest
task is now a no-op and all of the tests are now executed via a test,
yamlRestTest, javaRestTest, or internalClusterTest.

This includes the following projects:
security, spatial, stack, transform, vecotrs, voting-only-node, and watcher.

A few of the more specialized qa projects within these plugins
have not been changed with this PR due to additional complexity which should
be addressed separately. 

related: #60630
related: #56841
related: #59939
related: #55896
jakelandis added a commit that referenced this pull request Sep 8, 2020
This commit removes `integTest` task from all es-plugins.  
Most relevant projects have been converted to use yamlRestTest, javaRestTest, 
or internalClusterTest in prior PRs. 

A few projects needed to be adjusted to allow complete removal of this task
* x-pack/plugin - converted to use yamlRestTest and javaRestTest 
* plugins/repository-hdfs - kept the integTest task, but use `rest-test` plugin to define the task
* qa/die-with-dignity - convert to javaRestTest
* x-pack/qa/security-example-spi-extension - convert to javaRestTest
* multiple projects - remove the integTest.enabled = false (yay!)

related: #61802
related: #60630
related: #59444
related: #59089
related: #56841
related: #59939
related: #55896
jakelandis added a commit to jakelandis/elasticsearch that referenced this pull request Sep 8, 2020
This commit removes `integTest` task from all es-plugins.
Most relevant projects have been converted to use yamlRestTest, javaRestTest,
or internalClusterTest in prior PRs.

A few projects needed to be adjusted to allow complete removal of this task
* x-pack/plugin - converted to use yamlRestTest and javaRestTest
* plugins/repository-hdfs - kept the integTest task, but use `rest-test` plugin to define the task
* qa/die-with-dignity - convert to javaRestTest
* x-pack/qa/security-example-spi-extension - convert to javaRestTest
* multiple projects - remove the integTest.enabled = false (yay!)

related: elastic#61802
related: elastic#60630
related: elastic#59444
related: elastic#59089
related: elastic#56841
related: elastic#59939
related: elastic#55896
# Conflicts:
#	qa/die-with-dignity/src/javaRestTest/java/org/elasticsearch/qa/die_with_dignity/DieWithDignityIT.java
#	x-pack/qa/security-example-spi-extension/build.gradle
jakelandis added a commit that referenced this pull request Sep 9, 2020
This commit removes `integTest` task from all es-plugins.  
Most relevant projects have been converted to use yamlRestTest, javaRestTest, 
or internalClusterTest in prior PRs. 

A few projects needed to be adjusted to allow complete removal of this task
* x-pack/plugin - converted to use yamlRestTest and javaRestTest 
* plugins/repository-hdfs - kept the integTest task, but use `rest-test` plugin to define the task
* qa/die-with-dignity - convert to javaRestTest
* x-pack/qa/security-example-spi-extension - convert to javaRestTest
* multiple projects - remove the integTest.enabled = false (yay!)

related: #61802
related: #60630
related: #59444
related: #59089
related: #56841
related: #59939
related: #55896
@mark-vieira mark-vieira added Team:Delivery Meta label for Delivery team and removed Team:Core/Infra Meta label for core/infra team labels Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Delivery/Build Build or test infrastructure >refactoring Team:Delivery Meta label for Delivery team v7.8.1 v7.9.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants