diff --git a/test/e2e/framework/test_context.go b/test/e2e/framework/test_context.go index 400a043077a..6108cddf740 100644 --- a/test/e2e/framework/test_context.go +++ b/test/e2e/framework/test_context.go @@ -530,6 +530,14 @@ func AfterReadingAllFlags(t *TestContextType) { } } +const ( + // This is the traditional gomega.Format default of 4000 for an object + // dump plus some extra room for the message. + maxFailureMessageSize = 5000 + + truncatedMsg = "\n[... see output for full dump ...]\n" +) + // 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 @@ -546,6 +554,18 @@ func writeJUnitReport(report ginkgo.Report) { if specReport.State != types.SpecStateFailed { specReport.CapturedGinkgoWriterOutput = "" specReport.CapturedStdOutErr = "" + } else { + // Truncate the failure message if it is too large. + msgLen := len(specReport.Failure.Message) + if msgLen > maxFailureMessageSize { + // Insert full message at the beginning where it is easy to find. + specReport.CapturedGinkgoWriterOutput = + "Full failure message:\n" + + specReport.Failure.Message + "\n\n" + + strings.Repeat("=", 70) + "\n\n" + + specReport.CapturedGinkgoWriterOutput + specReport.Failure.Message = specReport.Failure.Message[0:maxFailureMessageSize/2] + truncatedMsg + specReport.Failure.Message[msgLen-maxFailureMessageSize/2:msgLen] + } } // Remove report entries generated by ginkgo.By("doing