Skip to content

Commit

Permalink
Revert "e2e: Trim junit reporter to adapt with testgrid"
Browse files Browse the repository at this point in the history
  • Loading branch information
endocrimes committed Aug 3, 2022
1 parent 49bcbe6 commit 5b31224
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 52 deletions.
60 changes: 8 additions & 52 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ import (
"fmt"
"math/rand"
"os"
"path"
"path/filepath"
"testing"
"time"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/ginkgo/v2/reporters"
"github.com/onsi/ginkgo/v2/types"
"gopkg.in/yaml.v2"

// Never, ever remove the line with "/ginkgo". Without it,
Expand Down Expand Up @@ -146,9 +143,10 @@ var _ = ginkgo.ReportAfterEach(func(report ginkgo.SpecReport) {
progressReporter.ProcessSpecReport(report)
})

// writeSpecSummaryOutput will output details about every test (name, files, lines, etc) which helps
// when documenting our tests.
func writeSpecSummaryOutput(report ginkgo.Report) {
var _ = ginkgo.ReportAfterSuite("Kubernetes e2e suite report", func(report ginkgo.Report) {
var err error
// The DetailsRepoerter will output details about every test (name, files, lines, etc) which helps
// when documenting our tests.
if len(framework.TestContext.SpecSummaryOutput) <= 0 {
return
}
Expand All @@ -171,58 +169,16 @@ func writeSpecSummaryOutput(report ginkgo.Report) {
klog.Errorf("Error in detail reporter: %v", err)
return
}
if _, err = f.Write(b); err != nil {
_, err = f.Write(b)
if err != nil {
klog.Errorf("Error saving test details in detail reporter: %v", err)
return
}
// Printing newline between records for easier viewing in various tools.
if _, err = fmt.Fprintln(f, ""); err != nil {
_, err = fmt.Fprintln(f, "")
if err != nil {
klog.Errorf("Error saving test details in detail reporter: %v", err)
return
}
}
}

// writeJUnitReport generates a JUnit file in the e2e report directory that is
// shorter than the one normally written by `ginkgo --junit-report`. This is
// needed because the full report can become too large for tools like Spyglass
// (https://github.com/kubernetes/kubernetes/issues/111510).
//
// Users who want the full report can use `--junit-report`.
func writeJUnitReport(report ginkgo.Report) {
if framework.TestContext.ReportDir == "" {
return
}

trimmedReport := report
trimmedReport.SpecReports = nil
for _, specReport := range report.SpecReports {
// Remove details for any spec that hasn't failed. In Prow,
// the test output captured in build-log.txt has all of this
// information, so we don't need it in the XML.
if specReport.State != types.SpecStateFailed {
// strip the "system-error" if the testcase is not failed.
specReport.CapturedGinkgoWriterOutput = ""
// strip the "system-out" if the testcase is not failed.
specReport.CapturedStdOutErr = ""
// strip some details for tracing each steps executed by Ginkgo, this is used to build the "system-out"
// while "system-out" is not shown by Spyglass if the testcase is not failed.
specReport.ReportEntries = nil

}

trimmedReport.SpecReports = append(trimmedReport.SpecReports, specReport)
}

// With Ginkgo v1, we used to write one file per parallel node. Now
// Ginkgo v2 automatically merges all results into a report for us. The
// 01 suffix is kept in case that users expect files to be called
// "junit_<prefix><number>.xml".
junitReport := path.Join(framework.TestContext.ReportDir, "junit_"+framework.TestContext.ReportPrefix+"01.xml")
reporters.GenerateJUnitReport(trimmedReport, junitReport)
}

var _ = ginkgo.ReportAfterSuite("Kubernetes e2e suite report", func(report ginkgo.Report) {
writeSpecSummaryOutput(report)
writeJUnitReport(report)
})
9 changes: 9 additions & 0 deletions test/e2e/framework/test_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"fmt"
"math"
"os"
"path"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -355,6 +356,14 @@ func CreateGinkgoConfig() (types.SuiteConfig, types.ReporterConfig) {
suiteConfig.RandomizeAllSpecs = true
// Turn on verbose by default to get spec names
reporterConfig.Verbose = true
// Enable JUnit output to the result directory, but only if not already specified
// via -junit-report.
if reporterConfig.JUnitReport == "" && TestContext.ReportDir != "" {
// With Ginkgo v1, we used to write one file per parallel node. Now Ginkgo v2 automatically
// merges all results into a single file for us. The 01 suffix is kept in case that users
// expect files to be called "junit_<prefix><number>.xml".
reporterConfig.JUnitReport = path.Join(TestContext.ReportDir, "junit_"+TestContext.ReportPrefix+"01.xml")
}
// Disable skipped tests unless they are explicitly requested.
if len(suiteConfig.FocusStrings) == 0 && len(suiteConfig.SkipStrings) == 0 {
suiteConfig.SkipStrings = []string{`\[Flaky\]|\[Feature:.+\]`}
Expand Down

0 comments on commit 5b31224

Please sign in to comment.