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

[SUREFIRE-2277] Fix bug in RunResult serialisation/deserialisation to (from) failsafe-summary.xml #790

Closed

Conversation

bingx1
Copy link

@bingx1 bingx1 commented Oct 11, 2024

This PR fixes the bug described in https://issues.apache.org/jira/browse/SUREFIRE-2277

Problem

There is a bug in RunResult.testAppendSerialization.

This test creates a RunResult object in-memory, serialises it, writes it to disk and then again deserialises the same file into a RunResult in-memory. I have run the test with the debugger and found that the final in-memory RunResult object is not the same as the initial one.

It shouldn't be passing on master, but is due to a bug in the RunResult.equals method which is used in an assertion in the test. The source of the bug is that the value of RunResult.flakes isn't preserved during serialisation to and from failsafe-summary.xml. The bug is slipping through and the test passes because the RunResult.equals method doesn't consider the RunResult.flakes field.

Fix

I have modified the failsafe-summary.xsd to include an optional <flakes> element, which will allow RunResult.flakes to be persisted in the failsafe-summary.xml during serialisation. I have also changed the serialisation and deserialisation methods for RunResult to account for flakes.

I have also added a test, RunResultTest.testLegacyDeserialization for backwards compatibility. It tests that deserialising a legacy failsafe-summary.xml still works. The behaviour is that when the flakes XML element is not present in the failsafe-summary.xml, the in-memory RunResult will have RunResult.flakes set to 0 after deserialisation.


Following this checklist to help us incorporate your
contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without
    pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [SUREFIRE-XXX] - Fixes bug in ApproximateQuantiles,
    where you replace SUREFIRE-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the
    commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its clean install).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

Our company, Atlassian, has a corporate CLA signed, and we added our team to it.
Contributors: Alex Courtis, Bing Xu and Hubert Grzeskowiak

@@ -64,6 +69,49 @@ public void testSkipped() throws Exception {
writeReadCheck(new RunResult(3, 2, 1, 0, null, true));
}

@Test
public void testFlakes() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you be more specific about the exception thrown?

}

@Test
public void testLegacyDeserialization() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you be more specific about the exception thrown?

Copy link
Author

Choose a reason for hiding this comment

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

Hey, yeah I could but it's a test method, I'm not convinced it's necessary to be specific here. I was following the existing code style in this particular Test class. I think in this case it may be better to be consistent with the original style.

Copy link
Contributor

Choose a reason for hiding this comment

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

I 100% disagree. Consistency with imperfect code is not a virtue. New code should follow best practices, even when the old code does not.

Copy link
Member

@michael-o michael-o left a comment

Choose a reason for hiding this comment

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

Willing to merge when open issue are addressed.

@michael-o
Copy link
Member

I have corrected the line ending of all XSD files, please rebase and we will run ITs.

…the equals method for RunResult where it did not account for the flakes field.
@bingx1 bingx1 force-pushed the fix-runresult-serialisation-bug branch from ac0efac to 9d2afac Compare October 29, 2024 12:14
…mary.xsd for the

flakes element. Add a comment noting that flakes will be expected in the
failsafe-summary in the future.

Incorporate the value of flakes into RunResult.hashCode() to be
consistent with the new implementation of toEquals
@bingx1 bingx1 force-pushed the fix-runresult-serialisation-bug branch from 9d2afac to 73641e7 Compare October 29, 2024 12:17
@bingx1
Copy link
Author

bingx1 commented Oct 29, 2024

I have corrected the line ending of all XSD files, please rebase and we will run ITs.

Done

@michael-o michael-o self-requested a review October 29, 2024 12:57
@michael-o michael-o closed this in d24adb4 Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants