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

If a test failure isn't found in the test case map, try to assign it to the suite matching a class that is #15023

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gmishkin
Copy link

Mockito unnecessary stubbing detection (org.mockito.exceptions.misusing.UnnecessaryStubbingException) fires off failures outside the context of a test case, but since the Description isn't found in testsMap, the details aren't written to the test.xml (however it still goes to stdout and the overall bazel test fails).

This change attempts to look up a matching suite in the test map by its Class. If found, it creates a new test case node and marks it as failed. I tried using the dynamicTestFailure thingy directly on the suite, and that would increase the failure count, but the failure details wouldn't be added to the XML.

@@ -183,6 +184,18 @@ public void testFailure(Description description, Throwable throwable) {
test.testFailure(throwable, now());
}
}
else {
final Optional<Description> matchingSuite = testsMap.keySet().stream()
Copy link
Member

Choose a reason for hiding this comment

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

I think it's worth adding a comment indicating how this scenario occurs and what the motivation for the code is.

final TestCaseNode newTest = new TestCaseNode(description, suite);
suite.addTestCase(newTest);
testsMap.put(description, newTest);
newTest.testFailure(throwable, now());
Copy link
Member

Choose a reason for hiding this comment

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

TestNode differentiates between testFailure and dynamicTestFailure. I'm not familiar with this code, but would it not be better to do this as well?

Perhaps the code should be written so the logic to get a TestNode object (and update the map) comes at the top, and then the original code just operates on that?

Copy link
Author

Choose a reason for hiding this comment

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

@c-mita for this particular kind of exception, at least, when I try replacing the call to testFailure with dynamicTestFailure, I don't get a full stack trace in the final XML, despite passing through the Throwable.

So I'm a little hesitant to reorder the logic, because I don't understand the circumstances under which a DynamicTestException will appear in the top part of the if statement.

Copy link
Member

Choose a reason for hiding this comment

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

After a little more investigation, I believe that DynamicTestException is unused within Bazel.

It is used within Google however, so some care is needed. I'll need to investigate a bit more as changes here could have impacts beyond Bazel's test exection.

Copy link
Member

Choose a reason for hiding this comment

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

That using dynamicTestFailure all the time surpresses full stack traces doesn't surprise me, because that appears to be part of its intent. Its origin lies in handling Javascript test suites (which is an area I have no expertise in).

But the code I had in mind was this:

if (throwable instanceof DynamicTestException) {
  DynamicTestException dynamicFailure = (DynamicTestException) throwable;
  newTest.dynamicTestFailure(dynamicFailure.getTest(), dynamicFailure.getCause(), now());
} else {
  newTest.testFailure(throwable, now());
}

Essentially replicating what's done in the method above.

Copy link
Author

Choose a reason for hiding this comment

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

Moved the logic into getTest() think that's what you meant originally.

Copy link
Member

Choose a reason for hiding this comment

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

This means this new logic will run for more than just test failures; I don't know if this is a good thing or not.

@sgowroji sgowroji added team-Rules-Java Issues for Java rules labels Apr 7, 2022
@sgowroji
Copy link
Member

Hello @gmishkin, Can you please resolve the above comments and send back for review. Thanks!

@sgowroji sgowroji added the awaiting-user-response Awaiting a response from the author label Apr 21, 2022
@gmishkin
Copy link
Author

gmishkin commented Apr 25, 2022

@sgowroji I am just waiting for the outcome of the internal investigation in #15023 (comment) before proceeding further. I could start typing up a code comment for the first review comment above, but it'd simply be restating the pull request description, and I'd rather wait til the other comment is resolved in case it affects the patch or wording.

@gmishkin gmishkin requested a review from c-mita April 25, 2022 18:33
@sgowroji sgowroji added awaiting-review PR is awaiting review from an assigned reviewer and removed awaiting-user-response Awaiting a response from the author labels May 18, 2022
@gmishkin gmishkin force-pushed the assign-unexpected-tests-to-matching-suite-2 branch from c8e90be to 13ff0f1 Compare February 28, 2023 21:41
@gmishkin
Copy link
Author

gmishkin commented Mar 1, 2023

@c-mita the tests that are failing don't look like they're related to these changes, please advise if you think there's something I need to take a closer look at.

@c-mita
Copy link
Member

c-mita commented Mar 6, 2023

@c-mita the tests that are failing don't look like they're related to these changes, please advise if you think there's something I need to take a closer look at.

After cursory glance, I don't think your change is causing those failures.

return test;
}

final Optional<Description> matchingSuite = testsMap.keySet().stream()
Copy link
Member

Choose a reason for hiding this comment

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

This still needs a comment explaining why this is being done.

Especially considering that now a "getTest" method can result in internal state being changed.

@hvadehra hvadehra added awaiting-user-response Awaiting a response from the author and removed awaiting-review PR is awaiting review from an assigned reviewer labels Apr 13, 2023
raviagarwal7 pushed a commit to uber-common/bazel that referenced this pull request Jul 8, 2023
raviagarwal7 pushed a commit to uber-common/bazel that referenced this pull request Jul 10, 2023
raviagarwal7 pushed a commit to uber-common/bazel that referenced this pull request Jul 10, 2023
raviagarwal7 pushed a commit to uber-common/bazel that referenced this pull request Jul 26, 2023
raviagarwal7 pushed a commit to uber-common/bazel that referenced this pull request Jul 26, 2023
ckilian867 pushed a commit to uber-common/bazel that referenced this pull request Feb 27, 2024
raviagarwal7 pushed a commit to uber-common/bazel that referenced this pull request Mar 28, 2024
raviagarwal7 pushed a commit to uber-common/bazel that referenced this pull request Jul 1, 2024
raviagarwal7 pushed a commit to uber-common/bazel that referenced this pull request Aug 14, 2024
raviagarwal7 pushed a commit to uber-common/bazel that referenced this pull request Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-user-response Awaiting a response from the author team-Rules-Java Issues for Java rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants