diff --git a/ginkgo/internal/profiles_and_reports.go b/ginkgo/internal/profiles_and_reports.go index 8e16d2bb0..1d4116e7a 100644 --- a/ginkgo/internal/profiles_and_reports.go +++ b/ginkgo/internal/profiles_and_reports.go @@ -107,13 +107,13 @@ func FinalizeProfilesAndReportsForSuites(suites TestSuites, cliConfig types.CLIC } switch suite.State { case TestSuiteStateFailedToCompile: - report.SpecialSuiteFailureReasons = append(report.SpecialSuiteFailureReasons, suite.CompilationError.Error()) + report.AddSpecialSuiteFailureReasons(suite.CompilationError.Error()) case TestSuiteStateFailedDueToTimeout: - report.SpecialSuiteFailureReasons = append(report.SpecialSuiteFailureReasons, TIMEOUT_ELAPSED_FAILURE_REASON) + report.AddSpecialSuiteFailureReasons(TIMEOUT_ELAPSED_FAILURE_REASON) case TestSuiteStateSkippedDueToPriorFailures: - report.SpecialSuiteFailureReasons = append(report.SpecialSuiteFailureReasons, PRIOR_FAILURES_FAILURE_REASON) + report.AddSpecialSuiteFailureReasons(PRIOR_FAILURES_FAILURE_REASON) case TestSuiteStateSkippedDueToEmptyCompilation: - report.SpecialSuiteFailureReasons = append(report.SpecialSuiteFailureReasons, EMPTY_SKIP_FAILURE_REASON) + report.AddSpecialSuiteFailureReasons(EMPTY_SKIP_FAILURE_REASON) report.SuiteSucceeded = true } diff --git a/internal/suite.go b/internal/suite.go index a3c9e6bf1..a0352be75 100644 --- a/internal/suite.go +++ b/internal/suite.go @@ -468,7 +468,7 @@ func (suite *Suite) runSpecs(description string, suiteLabels Labels, suitePath s for { groupedSpecIdx, err := nextIndex() if err != nil { - suite.report.SpecialSuiteFailureReasons = append(suite.report.SpecialSuiteFailureReasons, fmt.Sprintf("Failed to iterate over specs:\n%s", err.Error())) + suite.report.AddSpecialSuiteFailureReasons(fmt.Sprintf("Failed to iterate over specs:\n%s", err.Error())) suite.report.SuiteSucceeded = false break } @@ -490,12 +490,12 @@ func (suite *Suite) runSpecs(description string, suiteLabels Labels, suitePath s } if suite.config.FailOnPending && specs.HasAnySpecsMarkedPending() { - suite.report.SpecialSuiteFailureReasons = append(suite.report.SpecialSuiteFailureReasons, "Detected pending specs and --fail-on-pending is set") + suite.report.AddSpecialSuiteFailureReasons("Detected pending specs and --fail-on-pending is set") suite.report.SuiteSucceeded = false } if suite.config.FailOnEmpty && specs.CountWithoutSkip() == 0 { - suite.report.SpecialSuiteFailureReasons = append(suite.report.SpecialSuiteFailureReasons, "Detected no specs ran and --fail-on-empty is set") + suite.report.AddSpecialSuiteFailureReasons("Detected no specs ran and --fail-on-empty is set") suite.report.SuiteSucceeded = false } } @@ -506,13 +506,13 @@ func (suite *Suite) runSpecs(description string, suiteLabels Labels, suitePath s interruptStatus := suite.interruptHandler.Status() if interruptStatus.Interrupted() { - suite.report.SpecialSuiteFailureReasons = append(suite.report.SpecialSuiteFailureReasons, interruptStatus.Cause.String()) + suite.report.AddSpecialSuiteFailureReasons(interruptStatus.Cause.String()) suite.report.SuiteSucceeded = false } suite.report.EndTime = time.Now() suite.report.RunTime = suite.report.EndTime.Sub(suite.report.StartTime) if !suite.deadline.IsZero() && suite.report.EndTime.After(suite.deadline) { - suite.report.SpecialSuiteFailureReasons = append(suite.report.SpecialSuiteFailureReasons, "Suite Timeout Elapsed") + suite.report.AddSpecialSuiteFailureReasons("Suite Timeout Elapsed") suite.report.SuiteSucceeded = false } @@ -540,7 +540,7 @@ func (suite *Suite) runBeforeSuite(numSpecsThatWillBeRun int) { suite.reporter.WillRun(suite.currentSpecReport) suite.runSuiteNode(beforeSuiteNode) if suite.currentSpecReport.State.Is(types.SpecStateSkipped) { - suite.report.SpecialSuiteFailureReasons = append(suite.report.SpecialSuiteFailureReasons, "Suite skipped in BeforeSuite") + suite.report.AddSpecialSuiteFailureReasons("Suite skipped in BeforeSuite") suite.skipAll = true } suite.processCurrentSpecReport() diff --git a/types/types.go b/types/types.go index aae69b04c..7df4d2a57 100644 --- a/types/types.go +++ b/types/types.go @@ -72,17 +72,21 @@ type PreRunStats struct { // Add is used by Ginkgo's parallel aggregation mechanisms to combine test run reports form individual parallel processes // to form a complete final report. -func (report Report) Add(other Report) Report { - report.SuiteSucceeded = report.SuiteSucceeded && other.SuiteSucceeded +func (report *Report) Add(other Report) Report { + newReport := *report + newReport.SuiteSucceeded = report.SuiteSucceeded && other.SuiteSucceeded if other.StartTime.Before(report.StartTime) { - report.StartTime = other.StartTime + newReport.StartTime = other.StartTime } if other.EndTime.After(report.EndTime) { - report.EndTime = other.EndTime + newReport.EndTime = other.EndTime } + newReport.RunTime = newReport.EndTime.Sub(newReport.StartTime) + + // combine specialSuiteFailureReasons without duplicates specialSuiteFailureReasons := []string{} reasonsLookup := map[string]bool{} for _, reasons := range [][]string{report.SpecialSuiteFailureReasons, other.SpecialSuiteFailureReasons} { @@ -93,18 +97,22 @@ func (report Report) Add(other Report) Report { } } } - report.SpecialSuiteFailureReasons = specialSuiteFailureReasons - report.RunTime = report.EndTime.Sub(report.StartTime) + newReport.SpecialSuiteFailureReasons = specialSuiteFailureReasons + // combine reports reports := make(SpecReports, len(report.SpecReports)+len(other.SpecReports)) copy(reports, report.SpecReports) offset := len(report.SpecReports) for i := range other.SpecReports { reports[i+offset] = other.SpecReports[i] } + newReport.SpecReports = reports + + return newReport +} - report.SpecReports = reports - return report +func (report *Report) AddSpecialSuiteFailureReasons(reason string) { + report.SpecialSuiteFailureReasons = append(report.SpecialSuiteFailureReasons, reason) } // SpecReport captures information about a Ginkgo spec.