Skip to content

Flaky failure #226

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 178 additions & 8 deletions test/converters/junitxml/junitxml.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,191 @@ func convertTestReport(report TestReport) testreport.TestReport {

func convertTestSuite(testSuite TestSuite) testreport.TestSuite {
convertedTestSuite := testreport.TestSuite{
XMLName: testSuite.XMLName,
Name: testSuite.Name,
Tests: testSuite.Tests,
Failures: testSuite.Failures + testSuite.Errors,
Skipped: testSuite.Skipped,
Time: testSuite.Time,
XMLName: testSuite.XMLName,
Name: testSuite.Name,
Time: testSuite.Time,
}

for _, testCase := range testSuite.TestCases {
tests := 0
failures := 0
skipped := 0

flattenedTestCases := flattenGroupedTestCases(testSuite.TestCases)
for _, testCase := range flattenedTestCases {
convertedTestCase := convertTestCase(testCase)
convertedTestSuite.TestCases = append(convertedTestSuite.TestCases, convertedTestCase)

if convertedTestCase.Failure != nil {
failures++
}
if convertedTestCase.Skipped != nil {
skipped++
}
tests++
}

convertedTestSuite.Tests = tests
convertedTestSuite.Failures = failures
convertedTestSuite.Skipped = skipped

return convertedTestSuite
}

func flattenGroupedTestCases(testCases []TestCase) []TestCase {
var flattenedTestCases []TestCase
for _, testCase := range testCases {
flattenedTestCases = append(flattenedTestCases, testCase)

if len(testCase.FlakyFailures) == 0 && len(testCase.FlakyErrors) == 0 &&
len(testCase.RerunFailures) == 0 && len(testCase.RerunErrors) == 0 {
continue
}

flattenedTestCase := TestCase{
XMLName: testCase.XMLName,
ConfigurationHash: testCase.ConfigurationHash,
Name: testCase.Name,
ClassName: testCase.ClassName,
Time: 0,
Failure: nil,
Skipped: nil,
Error: nil,
FlakyFailures: nil,
Copy link

Choose a reason for hiding this comment

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

If you want to be explicit about leaving these empty, also add FlakyErrors and RetryErrors.
Or just leave them all out.

RerunFailures: nil,
Comment on lines +124 to +129
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you do not need to explicitly set these and omit them because they will be initialised to their default value which are what you just described here.

}

for _, flakyFailure := range testCase.FlakyFailures {
flattenedTestCase.Failure = convertFlakyFailureToFailure(flakyFailure)
flattenedTestCases = append(flattenedTestCases, flattenedTestCase)
}

for _, flakyError := range testCase.FlakyErrors {
flattenedTestCase.Failure = convertFlakyErrorToFailure(flakyError)
flattenedTestCases = append(flattenedTestCases, flattenedTestCase)
}

for _, rerunfailure := range testCase.RerunFailures {
flattenedTestCase.Failure = convertRerunFailureToFailure(rerunfailure)
flattenedTestCases = append(flattenedTestCases, flattenedTestCase)
}

for _, rerunError := range testCase.RerunErrors {
flattenedTestCase.Failure = convertRerunErrorToFailure(rerunError)
flattenedTestCases = append(flattenedTestCases, flattenedTestCase)
Copy link

Choose a reason for hiding this comment

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

convertXXXToFailure is the same code 4x (insert rant about Go "interfaces").
Could we maybe replace them/delegate to something like convertToFailure(type, message, systemErr string)?

}

}
return flattenedTestCases
}

func convertFlakyFailureToFailure(flakyFailure FlakyFailure) *Failure {
var message string
if len(strings.TrimSpace(flakyFailure.Type)) > 0 {
message = flakyFailure.Type
}
if len(strings.TrimSpace(flakyFailure.Message)) > 0 {
if len(message) > 0 {
message += ": "
}
message += flakyFailure.Message
}

if len(strings.TrimSpace(flakyFailure.SystemErr)) > 0 {
if len(message) > 0 {
message += "\n\n"
}
message += "System error:\n" + flakyFailure.SystemErr
}

if len(message) > 0 {
return &Failure{
Value: message,
}
}
return nil
}

func convertFlakyErrorToFailure(flakyError FlakyError) *Failure {
var message string
if len(strings.TrimSpace(flakyError.Type)) > 0 {
message = flakyError.Type
}
if len(strings.TrimSpace(flakyError.Message)) > 0 {
if len(message) > 0 {
message += ": "
}
message += flakyError.Message
}

if len(strings.TrimSpace(flakyError.SystemErr)) > 0 {
if len(message) > 0 {
message += "\n\n"
}
message += "System error:\n" + flakyError.SystemErr
}

if len(message) > 0 {
return &Failure{
Value: message,
}
}
return nil
}

func convertRerunFailureToFailure(rerunFailure RerunFailure) *Failure {
var message string
if len(strings.TrimSpace(rerunFailure.Type)) > 0 {
message = rerunFailure.Type
}
if len(strings.TrimSpace(rerunFailure.Message)) > 0 {
if len(message) > 0 {
message += ": "
}
message += rerunFailure.Message
}

if len(strings.TrimSpace(rerunFailure.SystemErr)) > 0 {
if len(message) > 0 {
message += "\n\n"
}
message += "System error:\n" + rerunFailure.SystemErr
}

if len(message) > 0 {
return &Failure{
Value: message,
}
}
return nil
}

func convertRerunErrorToFailure(rerunError RerunError) *Failure {
var message string
if len(strings.TrimSpace(rerunError.Type)) > 0 {
message = rerunError.Type
}
if len(strings.TrimSpace(rerunError.Message)) > 0 {
if len(message) > 0 {
message += ": "
}
message += rerunError.Message
}

if len(strings.TrimSpace(rerunError.SystemErr)) > 0 {
if len(message) > 0 {
message += "\n\n"
}
message += "System error:\n" + rerunError.SystemErr
}

if len(message) > 0 {
return &Failure{
Value: message,
}
}
return nil
}
Comment on lines +156 to +262
Copy link
Contributor

Choose a reason for hiding this comment

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

These are identical functions with different parameter type but the used variables are the same on that given type.

We could simplify this by receiving the actual variables as parameters:

func convertToFailure(itemType, failureMessage, systemErr string) *Failure {
	var message string
	if len(strings.TrimSpace(itemType)) > 0 {
		message = itemType
	}
	if len(strings.TrimSpace(failureMessage)) > 0 {
		if len(message) > 0 {
			message += ": "
		}
		message += failureMessage
	}

	if len(strings.TrimSpace(systemErr)) > 0 {
		if len(message) > 0 {
			message += "\n\n"
		}
		message += "System error:\n" + systemErr
	}

	if len(message) > 0 {
		return &Failure{
			Value: message,
		}
	}
	return nil
}


func convertTestCase(testCase TestCase) testreport.TestCase {
convertedTestCase := testreport.TestCase{
XMLName: testCase.XMLName,
Expand Down Expand Up @@ -141,7 +310,8 @@ func convertErrorsToFailure(failure *Failure, error *Error, systemErr string) *t

if len(messages) > 0 {
return &testreport.Failure{
Value: strings.Join(messages, "\n\n"),
XMLName: xml.Name{Local: "failure"},
Value: strings.Join(messages, "\n\n"),
}
}
return nil
Expand Down
Loading