From 5eb99a0ac88a6d65d11d307c87043f42b0df07be Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Fri, 21 Apr 2023 14:25:36 +0200 Subject: [PATCH] test/e2e: fix custom timing reporting This never worked when ginkgo runs with more than one thread, we use 3 in CI. The problem is that the SynchronizedAfterSuite() function accepts two functions. The first one is run for each ginkgo node while the second one is only run once for the whole suite. Because the timings are stored as slice thus in memory we loose all timings from the other nodes as they were only reported on node 1. Moving the printing in the first function solves this but causes the problem that the result is now no longer sorted. To fix this we let each node write the result to a tmp file and only then let the final after suite function collect the timings from all these files, then sort them and print the output like we did before. Signed-off-by: Paul Holzinger --- test/e2e/common_test.go | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index 429df12e20..421836b0fd 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -1,6 +1,7 @@ package integration import ( + "bufio" "bytes" "errors" "fmt" @@ -167,11 +168,40 @@ func (p *PodmanTestIntegration) Setup() { INTEGRATION_ROOT = filepath.Join(cwd, "../../") } -var _ = SynchronizedAfterSuite(func() {}, +var _ = SynchronizedAfterSuite(func() { + f, err := os.Create(fmt.Sprintf("%s/timings-%d", LockTmpDir, GinkgoParallelProcess())) + Expect(err).ToNot(HaveOccurred()) + defer f.Close() + for _, result := range testResults { + _, err := f.WriteString(fmt.Sprintf("%s\t\t%f\n", result.name, result.length)) + Expect(err).ToNot(HaveOccurred(), "write timings") + } +}, func() { - sort.Sort(testResultsSortedLength{testResults}) + testTimings := make(testResultsSorted, 0, 2000) + for i := 1; i <= GinkgoT().ParallelTotal(); i++ { + f, err := os.Open(fmt.Sprintf("%s/timings-%d", LockTmpDir, i)) + Expect(err).ToNot(HaveOccurred()) + defer f.Close() + scanner := bufio.NewScanner(f) + for scanner.Scan() { + text := scanner.Text() + timing := strings.SplitN(text, "\t\t", 2) + if len(timing) != 2 { + Fail(fmt.Sprintf("incorrect timing line: %q", text)) + } + name := timing[0] + duration, err := strconv.ParseFloat(timing[1], 64) + Expect(err).ToNot(HaveOccurred(), "failed to parse float from timings file") + testTimings = append(testTimings, testResult{name: name, length: duration}) + } + if err := scanner.Err(); err != nil { + Expect(err).ToNot(HaveOccurred(), "read timings %d", i) + } + } + sort.Sort(testResultsSortedLength{testTimings}) GinkgoWriter.Println("integration timing results") - for _, result := range testResults { + for _, result := range testTimings { GinkgoWriter.Printf("%s\t\t%f\n", result.name, result.length) }