Skip to content

Testing conventions: add support for checking base classes#36650

Merged
alpar-t merged 17 commits intoelastic:masterfrom
alpar-t:testing-conventions-base-classes
Jan 8, 2019
Merged

Testing conventions: add support for checking base classes#36650
alpar-t merged 17 commits intoelastic:masterfrom
alpar-t:testing-conventions-base-classes

Conversation

@alpar-t
Copy link
Copy Markdown
Contributor

@alpar-t alpar-t commented Dec 14, 2018

Closes #33524

The PR is not as big as it seems, it adds a bunch of dummy classes to cover testing scenarios.

With this PR testing conventions can check that tests with a specific suffix extend from a specific list of base classes.
Both the suffixes and the base classes are configurable.
This now covers all the checks of namingConventions which will be removed in a subsequent PR.

We now also have tests for all the checks that naming conventions implement,
for good reason because the test uncovered that problems were not reported as they should. That's also fixed now.

Functionality to look for tasks in subprojects that run the tests is removed, and we disable the check on the parents instead. This was not working as intended and it's tricky to implement correctly because the tests are compiled for each subproject so we would need to load the test classes of the sub-projects too.
It's not worth the effort since we eventually check those tests for all sub-projects and would
catch any miss-configurations.

There are some other fixes to make the checks pass, like enabling integ tests on sql to pick up some tests that don't currently.

@elasticmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-core-infra


@SuppressWarnings("unused")
public void testUsage() throws IOException, InterruptedException {
public void usage() throws IOException, InterruptedException {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These are for documentation only, not tests, it's not code we run and the method name is not important.
I changed it because testing conventions picked up the method name.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I thought we did execute these. In my opinion, it is important to execute the examples that we have in the docs. They may not assert all that much, but at a minimum they shouldn't crash and it'd be nice if we made them assert things that matched the prose. Which we often do and might do here as well.

Copy link
Copy Markdown
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

I see the usefulness for this between the gradle testing side and the rest of our code. But, outside of server's integTest (which we can fix by renaming to internalClusterTest as xpack already has), where do we have divergence from the set naming conventions? While I understand the advantage of general purpose configurability for gradle plugins in general, making these configurable within our own project lends to different subprojects having different conventions. I think consistency across so many subprojects is paramount. So, I am ok with this PR from the perspective of making it configurable for build-tools to use, but I think it should be configured programmatically so that when we construct the naming convention task, it is set and cannot be changed.

}

testingConventions {
naming.clear()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need this clear()? I don't like the leniency it provides. If we want to provide the ability to replace completely, then let's have a set version (much like many task settings can be set with = instead of calling DSL-like methods for adding).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We do have a set method, so one can write something like baseClasses = [...] to replace what was already there. The clear comes from the Gradle container in which the rules live and it's consistent with how Gradle behaves in general. Granted the clear method is not used often. The intent here is to remove a rule from the container. The default is rule for Tests and IT. If a project doesn't have both, the alternative is naming.remove(naming.getByName('Tests')). The semantics of clear are I think slightly better, because it expresses "I only have IT", rather than "I don't have Tests", it's also indicative that all the rules are configured right here and there can be nothing coming from configuration elsewhere. I don't hover have a strong preference.

I don't like it in general where we have a plugin configure something and then the project throws it out completely. We sometimes do this with disabling tasks as well.
There should be a way to ask only for what the project needs.

I also explain in the comment bellow that I view this as an intermediary step and don't want to keep rules as configurable, it's just a means to get to the point where everything follows conventions.

import java.util.Set;
import java.util.regex.Pattern;

public class TestingConventionRule implements Serializable {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add at least minimal javadocs. What would you want someone who has never seen this class to understand about it if they navigate here while reading through build code?

@alpar-t
Copy link
Copy Markdown
Contributor Author

alpar-t commented Dec 17, 2018

@rjernst I fully agree with what you said. Making it configurable defeats the purpose of conventions. I see this as the path to being able to enforce the conventions in full.
I haven't looked at all the places where conventions are diverged from, but I did see some internal cluster tests for plugins. I see this flexibility as a more convenient way to get to enforce the conventions without having list of exceptions. We would essentially start removing configuration from build.gradle files until there are no more left, then remove the ability to have a custom configuration at all.

@jasontedor jasontedor added v6.7.0 and removed v6.6.0 labels Dec 19, 2018
@jasontedor jasontedor requested a review from rjernst December 20, 2018 17:21
Copy link
Copy Markdown
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

Thanks @atorok for the explanation. I'm ok moving forward with this, but want to be sure this state does not exist for long. Historically, anytime something like this is configurable, someone will (ab)use it somehow, and it makes it more difficult to remove.

*/
public class TestingConventionRule implements Serializable {

private final String name;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this should be "suffix" instead of "name"?

@alpar-t alpar-t merged commit 6344e9a into elastic:master Jan 8, 2019
@alpar-t alpar-t deleted the testing-conventions-base-classes branch January 8, 2019 11:39
@mark-vieira mark-vieira added the Team:Delivery Meta label for Delivery team label 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 >non-issue Team:Delivery Meta label for Delivery team v6.7.0 v7.0.0-beta1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build: NamingConventionsCheck's defaults are from a different era

7 participants