Skip to content

Commit 07fcbc1

Browse files
Update e2e diagnostics
Don't double print diagnostics, bypassing GinkgoWriter entirely to avoid duplication. Relying on CapturedGinkgoWriterOutput was causing the dupes.
1 parent 0acc63e commit 07fcbc1

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

e2e/e2e_common.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package e2e
1717
import (
1818
"context"
1919
"fmt"
20+
"os"
2021
"reflect"
2122
"strings"
2223
"time"
@@ -66,6 +67,11 @@ var (
6667
// ReportAfterEach dumps detailed state for each tracked resource then clears
6768
// the list.
6869
resourcesUnderTest []client.Object
70+
71+
// specDiagnostics stores per-spec diagnostic output keyed by spec text.
72+
// ReportAfterEach populates it on failure; ReportAfterSuite reads it to
73+
// append diagnostics to the JUnit failure message.
74+
specDiagnostics = map[string]string{}
6975
)
7076

7177
func init() {
@@ -113,16 +119,16 @@ func trackResource(obj client.Object) {
113119
resourcesUnderTest = append(resourcesUnderTest, obj)
114120
}
115121

116-
// dumpTrackedResources writes detailed diagnostics for each tracked resource
117-
// to GinkgoWriter. For each resource it fetches current state, marshals it as
122+
// collectTrackedResourceDiagnostics builds a diagnostics string for each
123+
// tracked resource. For each resource it fetches current state, marshals it as
118124
// YAML, and lists events specific to that object. It also dumps all
119125
// AWSMachineTemplates (on AWS) and all events in both namespaces.
120126
// Best-effort: panics are recovered and individual errors are logged without
121127
// aborting the dump.
122-
func dumpTrackedResources() {
128+
func collectTrackedResourceDiagnostics() string {
123129
defer func() {
124130
if r := recover(); r != nil {
125-
GinkgoWriter.Printf("WARNING: dumpTrackedResources panicked: %v\n", r)
131+
fmt.Fprintf(os.Stderr, "WARNING: collectTrackedResourceDiagnostics panicked: %v\n", r)
126132
}
127133
}()
128134

@@ -141,7 +147,7 @@ func dumpTrackedResources() {
141147

142148
buf.WriteString("\n=== End Test Failure Diagnostics ===\n")
143149

144-
GinkgoWriter.Print(buf.String())
150+
return buf.String()
145151
}
146152

147153
func dumpSingleResource(buf *strings.Builder, obj client.Object) {

e2e/e2e_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ var _ = BeforeSuite(func() {
3636

3737
var _ = ReportAfterEach(func(report SpecReport) {
3838
if report.Failed() {
39-
dumpTrackedResources()
39+
diag := collectTrackedResourceDiagnostics()
40+
specDiagnostics[report.LeafNodeLocation.String()] = diag
4041
}
4142

4243
resourcesUnderTest = nil
@@ -58,20 +59,15 @@ var _ = ReportAfterSuite("junit with diagnostics", func(report Report) {
5859
return
5960
}
6061

61-
// Append GinkgoWriter output (which contains our tracked resource dump)
62-
// to the failure description so it appears in the <failure> element of
63-
// the JUnit XML, which is what Spyglass renders by default.
6462
for i := range report.SpecReports {
6563
sr := &report.SpecReports[i]
6664
if !sr.Failed() {
6765
continue
6866
}
6967

70-
if sr.CapturedGinkgoWriterOutput == "" {
71-
continue
68+
if diag, ok := specDiagnostics[sr.LeafNodeLocation.String()]; ok {
69+
sr.Failure.Message += "\n\n" + diag
7270
}
73-
74-
sr.Failure.Message += "\n\n" + sr.CapturedGinkgoWriterOutput
7571
}
7672

7773
dst := filepath.Join(artifactDir, "junit_cluster_capi_operator.xml")

0 commit comments

Comments
 (0)