Skip to content

Commit

Permalink
test/e2e: fix custom timing reporting
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Luap99 committed May 2, 2023
1 parent 1bff010 commit 5eb99a0
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions test/e2e/common_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integration

import (
"bufio"
"bytes"
"errors"
"fmt"
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 5eb99a0

Please sign in to comment.