Skip to content
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

Use versioned sourceset for REST compat testing #78418

Merged
merged 19 commits into from
Oct 12, 2021

Conversation

jakelandis
Copy link
Contributor

@jakelandis jakelandis commented Sep 28, 2021

This commit changes the sourceset name for REST API compatility testing
from yamlRestCompatTest to yamlRestTestV(N)Compat wher (N) is the version
from which the tests are sourced. For example yamlRestTestV7Compat
or yamlRestTestV8Compat.

Two motivating reasons for this change.

  1. consitent naming - all compatible rest testing will now use a common
    prefix of yamlRestTestV7Compat where the task name to execute is
    yamlRestTestV7CompatTestand the transformation task is yamlRestTestV7CompatTransform
    It makes sense that corresponding source set follows this convention.

  2. Better support when the major version changes. Gradle uses the source
    set under the covers to execute the compatiblity tests. However, a user
    can add custom REST tests to this source set. By using dynamically named
    source sets, there should little concern of accidentally running the wrong
    version tests. Additionaly it is visualy easy to tell which version the tests are
    from.

This commit also removes the unecessary duplicated v7compat directory
and adds copy and classpath duplicate checks to ensure that we don't
accidentally stomp on duplicates with all of the copy and classpath manipulation.

related: #75267

@jakelandis jakelandis marked this pull request as ready for review September 30, 2021 16:28
@jakelandis jakelandis added :Delivery/Build Build or test infrastructure >non-issue labels Sep 30, 2021
@elasticmachine elasticmachine added the Team:Delivery Meta label for Delivery team label Sep 30, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-delivery (Team:Delivery)

@jakelandis jakelandis requested a review from pgomulka September 30, 2021 16:28
@@ -55,6 +54,7 @@
@Override
public void apply(Project project) {
final int compatibleVersion = Version.fromString(VersionProperties.getVersions().get("elasticsearch")).getMajor() - 1;
final String sourceSetName = "yamlRestTestV" + compatibleVersion + "Compat";
final Path compatRestResourcesDir = Path.of("restResources").resolve("v" + compatibleVersion);
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are having version-specific source sets, do we still need to capture the version here in the file path as well. As it is now we have files like src/yamlRestTestV7Compat/resources/rest-api-spec/test/v7compat/foo/bar.yml. We probably don't need to track the version twice now. Also begs the question whether we need this change in the first place if we are already managing per-version test resources. How will this affect backporting, etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

src/yamlRestTestV7Compat/resources/rest-api-spec/test/v7compat/foo/bar.yml uses a 4 part path to keept it from colliding with the actual v7 test/foo/bar.yml if it exists. (Both the real v7 tests and the custom test in this source set are on the same classpath, and there quite a bit of re-use of file names). v7compat in the path is just a convention and included the v7 to help demark these are intended for compatibilty with v7. The fact this is just a convention and without any teeth (i.e. these would execute when master is v9) is a motivating factor for this PR.

I can remove the v7 from the v7compat convention in this PR since I agree it doesn't make sense now. I think I could also remove this extra directory entirely and ensure uniqueness of the files between the two sources of tests (with validation in Gradle). Thoughts ?

Since our REST compatilbity only supports 1 major version, these should never be backported and anything in this sourceset should be removed in the next major version.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can remove the v7 from the v7compat convention in this PR since I agree it doesn't make sense now. I think I could also remove this extra directory entirely and ensure uniqueness of the files between the two sources of tests (with validation in Gradle). Thoughts ?

Yeah, I think that makes sense. It's just less stuff to try and keep in sync.

@@ -126,13 +127,15 @@ void copy() {

getLogger().debug("Rest specs for project [{}] will be copied to the test resources.", projectPath);
fileSystemOperations.copy(c -> {
c.setDuplicatesStrategy(DuplicatesStrategy.FAIL);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These duplicate fails are not actually needed for this PR, but I realized while adding the custom duplicate check to the compat testing task, it would be good to add a duplicate check here too.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is necessary since FAIL is now the default behavior in Gradle 7.0 and later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah.. it is. gradle/gradle#15759 I will remove this.

+ ".x] branch and the [" + sourceSetName + "] tests. ");
}
}
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

example of failure:

* What went wrong:
Execution failed for task ':rest-api-spec:yamlRestTestV7CompatTest'.
> Found duplicated test(s) [search/30_limits.yml] please ensure there not any duplicate YAML test files between the [7.x] branch and the [yamlRestTestV7Compat] tests. 

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if it might be better (and simpler) to implement this in the yaml testing framework code instead. It could be as simple as checking the result of the call to add() here and throwing an exception if it returns false.

@jakelandis
Copy link
Contributor Author

@mark-vieira - should be ready for another review. I implemented a duplicate check to ensure that the same test file is not on the class path more then once. 98% of the tests use 2 parts (foo/bar.yml) under the folder test and the duplicate check checks for those 2 parts. There is a slim chance of a false positive if a test uses 3 parts and the custom compat uses 2 part and there is name collision, but that is extremely unlikely.

I also removed the uncessary v7compat directory now that there is a proper check for duplicates.

@jakelandis
Copy link
Contributor Author

@elasticmachine update branch

+ ".x] branch and the [" + sourceSetName + "] tests. ");
}
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if it might be better (and simpler) to implement this in the yaml testing framework code instead. It could be as simple as checking the result of the call to add() here and throwing an exception if it returns false.

@sethmlarson sethmlarson added the Team:Clients Meta label for clients team label Oct 4, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/clients-team (Team:Clients)

@jakelandis
Copy link
Contributor Author

jakelandis commented Oct 12, 2021

I'm wondering if it might be better (and simpler) to implement this in the yaml testing framework code instead. It could be as simple as checking the result of the call to add() here and throwing an exception if it returns false.

Changed on 2a8fc87 (#78418)

It turns out we actually do support running duplicates on the classpath without stomping on each other. The framework will append a #2 to each test name. In light of this, i reduced the error down to a warning since which test (the first or the second with the same name) gets the #2 appended is dependent on the classloading order. We probably could add in some specific ordering of the collections so it wouldn't be classloader ordering but it would be some other non obvious ordering. The new warning is there in part to inform future developers that we actually do support duplicated names.

Example of the new warning message:

org.elasticsearch.test.rest.ClientYamlTestSuiteIT STANDARD_OUT
    [2021-10-11T19:44:38,076][WARN ][o.e.t.r.y.ESClientYamlSuiteTestCase] [[Test worker]] Found duplicate test name [search/10_source_filtering.yml] on the class path. This can result in class loader dependent execution commands and reproduction commands (will add #2 to one of the test names dependent on the classloading order)

I don't have a strong opinion to keep or leave this warning.

@jakelandis
Copy link
Contributor Author

@mark-vieira - finally got back round to this. should be ready for another review

Copy link
Contributor

@mark-vieira mark-vieira left a comment

Choose a reason for hiding this comment

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

LGTM

@jakelandis
Copy link
Contributor Author

@elasticmachine update branch

@jakelandis jakelandis merged commit ab221d7 into elastic:master Oct 12, 2021
@jakelandis jakelandis deleted the use_version_source_set branch October 12, 2021 23:25
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:Clients Meta label for clients team Team:Delivery Meta label for Delivery team v8.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants