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

Added flag to always include output in junit reports #327

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

alexxed
Copy link

@alexxed alexxed commented Apr 25, 2023

fixes #118

@@ -456,9 +438,6 @@ func (p *Package) addTestEvent(event TestEvent) {
if tc.Test.IsSubTest() {
return
}

Copy link
Author

@alexxed alexxed Apr 25, 2023

Choose a reason for hiding this comment

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

No test has failed, so I see no reason to remove the output from memory here, even if the flag is off. If we do want to remove it if the flag is off, due to memory concerns, need to pass the cfg up to here.

Copy link
Member

@dnephin dnephin May 4, 2023

Choose a reason for hiding this comment

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

Ya, the reason for deleting the output here is that it could be very large, and holding all the output in memory could cause problems in CI.

I'm wondering if we can change the JUnit XML file handling to be more like the jsonfile handling. That's done here:

gotestsum/cmd/handler.go

Lines 39 to 46 in 90a35cf

if err := writeWithNewline(h.jsonFile, event.Bytes()); err != nil {
return fmt.Errorf("failed to write JSON file: %w", err)
}
if event.Action.IsTerminal() {
if err := writeWithNewline(h.jsonFileTimingEvents, event.Bytes()); err != nil {
return fmt.Errorf("failed to write JSON file: %w", err)
}
}

If we can write the output each time a test passes or fails then we only need to buffer output for running tests, instead of buffering all of the output for every test in every package.

There will definitely be some challenges with that approach. The handler.Event runs after Package.addTestEvent, so the operation to "remove output" would need to move somewhere else, and there's currently no good place for it to move. The junit xml writer requires a lot more state than the jsonfile, so the implementation would be more involved.

Maybe the Junit XML writer could buffer the output itself, instead of relying on the buffer in Package.

Copy link
Member

Choose a reason for hiding this comment

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

It might also be possible to change the interface between handler and Package so that the output is returned before it is removed, but I'm not sure yet what that would look like.

@ethan-gallant
Copy link

I've tested this change in my Jenkins environment and can confirm it works as expected. It would be awesome if this could make it into a release 🚀

Copy link
Member

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! This is looking good, but as you noticed the big challenge here is how to buffer the output for running tests without having to keep the output of all tests in memory.

@@ -456,9 +438,6 @@ func (p *Package) addTestEvent(event TestEvent) {
if tc.Test.IsSubTest() {
return
}

Copy link
Member

@dnephin dnephin May 4, 2023

Choose a reason for hiding this comment

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

Ya, the reason for deleting the output here is that it could be very large, and holding all the output in memory could cause problems in CI.

I'm wondering if we can change the JUnit XML file handling to be more like the jsonfile handling. That's done here:

gotestsum/cmd/handler.go

Lines 39 to 46 in 90a35cf

if err := writeWithNewline(h.jsonFile, event.Bytes()); err != nil {
return fmt.Errorf("failed to write JSON file: %w", err)
}
if event.Action.IsTerminal() {
if err := writeWithNewline(h.jsonFileTimingEvents, event.Bytes()); err != nil {
return fmt.Errorf("failed to write JSON file: %w", err)
}
}

If we can write the output each time a test passes or fails then we only need to buffer output for running tests, instead of buffering all of the output for every test in every package.

There will definitely be some challenges with that approach. The handler.Event runs after Package.addTestEvent, so the operation to "remove output" would need to move somewhere else, and there's currently no good place for it to move. The junit xml writer requires a lot more state than the jsonfile, so the implementation would be more involved.

Maybe the Junit XML writer could buffer the output itself, instead of relying on the buffer in Package.

@@ -13,6 +13,7 @@ Flags:
--jsonfile string write all TestEvents to file
--jsonfile-timing-events string write only the pass, skip, and fail TestEvents to the file
--junitfile string write a JUnit XML file
--junitfile-always-include-output include output even on successful tests
Copy link
Member

Choose a reason for hiding this comment

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

Maybe --junit-include-output=all (with a default value of failures) or something like that? "always" I think doesn't make a clear distinction between the two modes: "all output", and "only failure output".

@alexxed
Copy link
Author

alexxed commented Jun 1, 2023

I'll get back to this eventually to address the feedback, meanwhile I pushed small change to address reruns problems. Currently if there is a rerun that passes, junit report will include both fail and pass, and tools that read that (e.g. Jenkins) will sum those up and consider the test failed.

@dnephin
Copy link
Member

dnephin commented Nov 4, 2023

Does anyone have an example of the schema that puts system-out under test-case ? If I look at all the top hits on google (https://github.com/windyroad/JUnit-Schema/blob/master/JUnit.xsd, https://github.com/testmoapp/junitxml, https://stackoverflow.com/a/9410271/444646) they put system-out as a sibling to test-case, which does not match the implementation in this PR.

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.

Include test output for successful tests in junitfile
3 participants