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

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

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

…the equals method for RunResult where it did not account for the flakes field.

return new RunResult(
parseInt(completed),
parseInt(errors),
parseInt(failures),
parseInt(skipped),
isBlank(flakes) ? 0 : parseInt(flakes),

Choose a reason for hiding this comment

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

nit: do you reckon it's worth adding a comment why we are treating this differently, i.e. because of backward compatibility?

@@ -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.

RunResult expected = new RunResult(3, 2, 1, 0, 0, null, false);
RunResult actual = FailsafeSummaryXmlUtils.toRunResult(legacySummary);

assertThat(actual.getCompletedCount()).isEqualTo(expected.getCompletedCount());
Copy link
Contributor

Choose a reason for hiding this comment

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

assertEquals is simpler and more obvious

Copy link
Author

Choose a reason for hiding this comment

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

Again, I wrote this assertion in such a way to be consistent with the other test methods in the same file. I can change it, but do I only change it in this test or in the existing code too? I also feel this assertion isn't particularly unclear

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.

4 participants