From 023baa5e45ddb9f59cd7ac9a09461fb31f47304b Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Mon, 24 Oct 2022 18:12:41 +0200 Subject: [PATCH] e2e framework: truncate too long failure messages when writing JUnit Our tooling cannot handle very long failure messages well: - when unfolding a test in the spyglass UI, it fills the entire screen - failure correlation for http://go.k8s.io/triage has resource constraints We cannot enforce that all tests only produce short failure messages and even if we could, depending on the test failure, including more information may be useful to understand it. To achieve both goals (summary for correlation and overview, all details available when digging deeper), too longer failure messages now get truncated, with the full message guaranteed to be captured in the test output. "Too long" is arbitrarily chosen to be similar to the gomega.MaxLength because that has been a limit for failure message size in the past. --- test/e2e/framework/test_context.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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