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

chore: Add Showcase Http Annotations Test #1568

Merged
merged 13 commits into from Mar 31, 2023
Merged

Conversation

lqiu96
Copy link
Contributor

@lqiu96 lqiu96 commented Mar 28, 2023

Thank you for opening a Pull Request! For general contributing guidelines, please refer to contributing guide

Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Part of #1439 ☕️

No longer blocked as #1522 has been merged in.

@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Mar 28, 2023
@lqiu96 lqiu96 marked this pull request as ready for review March 28, 2023 14:58
@lqiu96 lqiu96 requested a review from a team as a code owner March 28, 2023 14:58
@lqiu96
Copy link
Contributor Author

lqiu96 commented Mar 28, 2023

  JUnit Vintage:ITHttpAnnotation:testCompliance
    MethodSource [className = 'com.google.showcase.v1beta1.it.ITHttpAnnotation', methodName = 'testCompliance', methodParameterTypes = '']
    => org.opentest4j.MultipleFailuresError: Multiple Failures (2 failures)
	java.io.FileNotFoundException: src/test/resources/compliance_suite.json (No such file or directory)
	java.lang.NullPointerException: <no message>

I believe I need to include the compliance_suite.json file in the native build.

@lqiu96 lqiu96 mentioned this pull request Mar 28, 2023
27 tasks
@lqiu96 lqiu96 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 28, 2023
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 28, 2023
ComplianceSettings.newHttpJsonBuilder()
.setCredentialsProvider(NoCredentialsProvider.create())
.setTransportChannelProvider(
EchoSettings.defaultHttpJsonTransportProviderBuilder()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be ComplianceSettings instead of EchoSettings? Surprised it worked though.

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 yep, updated!

.gitignore Outdated
@@ -16,3 +16,5 @@ target/
.vscode/settings.json

*.iml

showcase/gapic-showcase/src/test/resources/compliance_suite.json
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should check it in if it is required for testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I can add it in.

}

@Test
public void testCompliance() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm actually not sure what we are verifying, can you make it clear with a better name and/or comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some comments and updated the test function's name.

@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Mar 29, 2023
for (String rpcName : validRpcList) {
for (RepeatRequest repeatRequest : compliancegroup.getRequestsList()) {
ComplianceData expectedData = repeatRequest.getInfo();
RepeatResponse response = complianceValidRpcMap.get(rpcName).apply(repeatRequest);
Copy link
Contributor

Choose a reason for hiding this comment

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

I like how you've structured this with the map.

Minor suggestion: I got caught on this line having to figure out what was going on. Consider the slightly more explicit:

for (String rpcName : validRpcList) {
    Function<Request, Response> rpc = complianceValidRpcMap.get(rpcName);
    for (Request request : getRequestsList()) {
        Response response = rpc.apply(request);
        ...
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will do!

@lqiu96 lqiu96 closed this Mar 29, 2023
@lqiu96 lqiu96 reopened this Mar 29, 2023
@lqiu96
Copy link
Contributor Author

lqiu96 commented Mar 29, 2023

@blakeli0 From our discussion earlier, I think we could split it up by ComplianceGroup and have a @test function for each group. Each group would be testing features like values and bindings against a series of RPCs. WDYT?

Comment on lines 89 to 99
for (ComplianceGroup compliancegroup : complianceSuite.getGroupList()) {
List<String> validRpcList =
compliancegroup.getRpcsList().stream()
.filter(complianceValidRpcMap::containsKey)
.collect(Collectors.toList());
for (String rpcName : validRpcList) {
Function<RepeatRequest, RepeatResponse> rpc = complianceValidRpcMap.get(rpcName);
for (RepeatRequest repeatRequest : compliancegroup.getRequestsList()) {
ComplianceData expectedData = repeatRequest.getInfo();
RepeatResponse response = rpc.apply(repeatRequest);
assertThat(response.getRequest().getInfo()).isEqualTo(expectedData);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could a helper method help reduce the number of nested for loops needed here? Reducing the amount of logic done in a test method can help with debugging in the future and prevent the test itself from developing bugs.

Copy link
Contributor Author

@lqiu96 lqiu96 Mar 29, 2023

Choose a reason for hiding this comment

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

Would it make more sense to just have each ComplianceGroup as its own test then? It could remove the outer most for loop if that's cleaner.

For each group, we test the product of rpcName and requestList.


Or did you mean something like:

  @Test
  public void testHttpAnnotations() {
    for (ComplianceGroup compliancegroup : complianceSuite.getGroupList()) {
      List<String> validRpcList =
          compliancegroup.getRpcsList().stream()
              .filter(complianceValidRpcMap::containsKey)
              .collect(Collectors.toList());
      helper(compliancegroup, validRpcList);
    }
  }

  private void helper(ComplianceGroup compliancegroup, List<String> validRpcList) {
    for (String rpcName : validRpcList) {
      Function<RepeatRequest, RepeatResponse> rpc = complianceValidRpcMap.get(rpcName);
      for (RepeatRequest repeatRequest : compliancegroup.getRequestsList()) {
        ComplianceData expectedData = repeatRequest.getInfo();
        RepeatResponse response = rpc.apply(repeatRequest);
        assertThat(response.getRequest().getInfo()).isEqualTo(expectedData);
      }
    }
  }

Copy link
Contributor

Choose a reason for hiding this comment

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

I do like the idea of splitting the test based on the ComplianceGroup since it would reduce cognitive load needed in understanding the behavior the test is trying to verify. Also, in the event that a test fails it will be easier to determine where/what behavior is failing.

Perhaps something similar to how ComplianceClientTest is structured.

Will also let @burkedavison and @blakeli0 weigh in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, makes sense. I've split them by ComplianceGroup (unless there is also hesitancy about this). The groups are split by behavior (i.e. bindings, weird/extreme values, templating, etc.) so a failure for a test case in testing one group should alert us to the problematic behavior.

Comment on lines 89 to 99
for (ComplianceGroup compliancegroup : complianceSuite.getGroupList()) {
List<String> validRpcList =
compliancegroup.getRpcsList().stream()
.filter(complianceValidRpcMap::containsKey)
.collect(Collectors.toList());
for (String rpcName : validRpcList) {
Function<RepeatRequest, RepeatResponse> rpc = complianceValidRpcMap.get(rpcName);
for (RepeatRequest repeatRequest : compliancegroup.getRequestsList()) {
ComplianceData expectedData = repeatRequest.getInfo();
RepeatResponse response = rpc.apply(repeatRequest);
assertThat(response.getRequest().getInfo()).isEqualTo(expectedData);
Copy link
Contributor

Choose a reason for hiding this comment

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

This may require a big change but was wondering - would it be possible to explicitly specify the expected value is without computing it?

Copy link
Contributor

Choose a reason for hiding this comment

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

As written, the compliance_suite.json is defined in a language-neutral way and can be (should?*) be owned by the gapic-showcase repo. If we hardcode expected values in the java test that duplicates the expected input, I would think this would eliminate our ability to have a common test suite defined elsewhere.

(*) Is there a way to get the compliance_suite.json from the gapic-showcase dependency rather than copying it into this repo?

Copy link
Contributor Author

@lqiu96 lqiu96 Mar 29, 2023

Choose a reason for hiding this comment

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

I'm a bit lost here (I might be misunderstanding the comments above). Is this not specifying the expected value: ComplianceData expectedData = repeatRequest.getInfo();? The test expects that showcase is able to return the Request's info properly back.

Is there a way to get the compliance_suite.json from the gapic-showcase dependency rather than copying it into this repo?

If I'm understand this correctly, the concern is that we may not be pulling in the latest/ specified json file version?

Right now, the json file is downloaded in the generate-test-resources maven lifecycle every time it's run. The file is versioned and downloads the from the gapic-showcase version in the pom file. It should be updated when we upgrade the gapic-showcase version and the file (with any changes) would be updated in this repo as well.

I had the json file ignored by git, but wasn't sure if it mattered. Since it's downloaded every time showcase is run, it'll always have the version we specify.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great - this is perfect.

I vote to .gitignore it since it's a "generated" file to avoid confusion over the source of truth; but the main concern you've already covered.

Thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. Going to loop in @blakeli0 again if he has some other concerns that might be missed. If not, I can add the file back into the .gitignore

Copy link
Contributor

Choose a reason for hiding this comment

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

re comment on hard-coding the expected value: Thanks for the clarification! I didn't take this aspect into account: I would think this would eliminate our ability to have a common test suite defined elsewhere. Given this reasoning, computing the value instead of hard-cording looks like the way to go.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I vote to .gitignore it since it's a "generated" file to avoid confusion over the source of truth; but the main concern you've already covered.

I feel it might be better to include this compliance_suite.json file in our repo and maybe the protos as well, as it would be easier to read and troubleshoot the tests. Even though they are "generated", but I consider them as part of the whole gapic-showcase test suite, just like the "generated" gapic client libraries, which are already included in our repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, added the json file in.

@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: l Pull request size is large. labels Mar 29, 2023
@lqiu96
Copy link
Contributor Author

lqiu96 commented Mar 30, 2023

@blakeli0 @burkedavison @mpeddada1 Could you all give a re-review whenever you all get a chance?

@@ -0,0 +1,119 @@
package com.google.showcase.v1beta1.it;
Copy link
Contributor

Choose a reason for hiding this comment

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

We may be missing a copyright header for this file?

Hm I wonder why our checkstyle didn't 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.

Added the copyright header. I'll need to check why it didn't run for the test files.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @lqiu96!

@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Mar 31, 2023
@sonarcloud
Copy link

sonarcloud bot commented Mar 31, 2023

[gapic-generator-java-root] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Mar 31, 2023

[java_showcase_integration_tests] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@sonarcloud
Copy link

sonarcloud bot commented Mar 31, 2023

[java_showcase_unit_tests] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@lqiu96
Copy link
Contributor Author

lqiu96 commented Mar 31, 2023

Let me know if the changes look fine @mpeddada1 @blakeli0

@lqiu96 lqiu96 merged commit d14875a into main Mar 31, 2023
18 checks passed
@lqiu96 lqiu96 deleted the main-showcase_compliance branch March 31, 2023 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants