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

Add support for regex in REST test warnings and allowed_warnings #69501

Merged
merged 8 commits into from
Mar 1, 2021

Conversation

jakelandis
Copy link
Contributor

@jakelandis jakelandis commented Feb 24, 2021

This commit adds support for two new REST test features.
warnings_regex and allowed_warnings_regex.

This is a near mirror of the warnings and allowed_warnings
warnings feature where the test can be instructed to allow
or require HTTP warnings. The difference with these new features
is that is allows the match to be based on a regular expression.

Also included in this PR is a new qa project rest-test-test
which can be used to exercise and validate the features of the
rest-test themselves. A rest test for the rest tests.

@jakelandis jakelandis added the WIP label Feb 24, 2021
@jakelandis
Copy link
Contributor Author

@elasticmachine update branch

@jakelandis jakelandis marked this pull request as ready for review February 24, 2021 21:20
@jakelandis jakelandis added :Delivery/Build Build or test infrastructure >non-issue v7.13.0 v8.0.0 and removed WIP labels Feb 24, 2021
@elasticmachine elasticmachine added the Team:Delivery Meta label for Delivery team label Feb 24, 2021
@elasticmachine
Copy link
Collaborator

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

@jakelandis
Copy link
Contributor Author

cc @elastic/es-clients -> this PR introduces two new features for the rest tests and ideally would be support across all of the clients tests.

@@ -51,7 +52,7 @@ public void testWarningHeaders() {
}

final String testHeader = HeaderWarning.formatWarning("test");
final String anotherHeader = HeaderWarning.formatWarning("another");
final String anotherHeader = HeaderWarning.formatWarning("another \"with quotes and \\ backslashes\"");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no actual changes here...just realized we didn't have any coverage for escaped character matching.

@sethmlarson
Copy link
Contributor

Thanks for the ping! Btw @jakelandis we're moving away from es-clients in favor of @elastic/clients-team.

@jakelandis
Copy link
Contributor Author

jakelandis commented Feb 24, 2021

Also note there will be a followup PR to allow injecting these for transformation, near identical to #69010

@jakelandis
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/1

@nik9000
Copy link
Member

nik9000 commented Feb 24, 2021

This commit adds support for two new REST test features.
warnings_regex and allowed_warnings_regex.

In other places in the framework we use / delimiters on strings to signal regexes. Its not the most precise thing but it never bothered me. Do we want to do _regex here?

@jakelandis
Copy link
Contributor Author

In other places in the framework we use / delimiters on strings to signal regexes. Its not the most precise thing but it never bothered me. Do we want to do _regex here?

I considered it, but it would be sneaky feature that could break the clients testing. For example, without support from the clients test could add a /Foo something .*/ would try to match the literal string and fail. This approach, while more verbose allows it live behind a feature gate.

import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;

public class ClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a number of tests in the :test:framework project itself to exercising the test framework. Is there a reason we can't put this stuff there? It seems like a much more appropriate place than introducing a new project to test a very specific piece of functionality that lives somewhere else. It would seem to me we could write an internal cluster test for this, which would remove the need to for an explicit plugin project just to declare a mock endpoint.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking more at what currently exists in terms of test coverage, I think just adding unit tests to the exist suite for this is sufficient. I think end-to-end testing with an external cluster is overkill here given we have no such equivalent testing for any of the other yaml rest testing functionality.

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 think end-to-end testing with an external cluster is overkill

Fair point especially since there little development in this area. Will remove the additional qa project. The unit tests are already included and provide pretty comprehensive coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

I left a small thing. Makes sense to me.

@@ -152,6 +152,15 @@ public void validate() {
"without a corresponding [\"skip\": \"features\": \"warnings\"] so runners that do not support the [warnings] " +
"section can skip the test at line [" + section.getLocation().lineNumber + "]");

errors = Stream.concat(errors, sections.stream().filter(section -> section instanceof DoSection)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if all this would become more readable if it were a for loop. Its certainly faster to copy and paste the blocks but maybe its time to redo?

* allowed_warnings:
* - The non _regex version exact matches against the warning text and no need to worry about escaped quotes or backslashes
* - The _regex version matches against the raw value of the warning text which may include backlashes and quotes escaped
* allowed_warnings|allowed_warnings_regex:
Copy link
Member

Choose a reason for hiding this comment

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

I might break out the regex ones just to show what a regex will look like. I agree on preferring the non-regex one. Its nice not to have to think about what punctuation means.

@jakelandis jakelandis merged commit 13915bc into elastic:master Mar 1, 2021
@jakelandis jakelandis deleted the warning_regex branch March 1, 2021 21:40
jakelandis added a commit to jakelandis/elasticsearch that referenced this pull request Mar 1, 2021
…stic#69501)

This commit adds support for two new REST test features.
warnings_regex and allowed_warnings_regex.

This is a near mirror of the warnings and allowed_warnings
warnings feature where the test can be instructed to allow
or require HTTP warnings. The difference with these new features
is that is allows the match to be based on a regular expression.
# Conflicts:
#	test/framework/src/main/java/org/elasticsearch/test/rest/yaml/Features.java
#	test/framework/src/test/java/org/elasticsearch/test/rest/yaml/section/DoSectionTests.java
jakelandis added a commit that referenced this pull request Mar 2, 2021
#69501) (#69754)

This commit adds support for two new REST test features.
warnings_regex and allowed_warnings_regex.

This is a near mirror of the warnings and allowed_warnings
warnings feature where the test can be instructed to allow
or require HTTP warnings. The difference with these new features
is that is allows the match to be based on a regular expression.
jakelandis added a commit that referenced this pull request Mar 16, 2021
This commit adds support to for injecting warnings_regex and
allowed_warnings_regex via test transformations used by
compatible testing.

related: #69501
related: #69010
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 v7.13.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants