mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-13 02:09:08 +02:00
[management] Drop the test store timing log and its summary column
The store helper is not a test file and should not carry a log line that only exists for the CI summary. The summarizer no longer parses it.
This commit is contained in:
@@ -687,7 +687,6 @@ func getMigrationsPostAuto(ctx context.Context) []migrationFunc {
|
||||
// NewTestStoreFromSQL is only used in tests. It will create a test database base of the store engine set in env.
|
||||
// Optionally it can load a SQL file to the database. If the filename is empty it will return an empty database
|
||||
func NewTestStoreFromSQL(ctx context.Context, filename string, dataDir string) (Store, func(), error) {
|
||||
start := time.Now()
|
||||
kind := getStoreEngineFromEnv()
|
||||
if kind == "" {
|
||||
kind = types.SqliteStoreEngine
|
||||
@@ -725,15 +724,10 @@ func NewTestStoreFromSQL(ctx context.Context, filename string, dataDir string) (
|
||||
var sqlStore Store
|
||||
var cleanup func()
|
||||
|
||||
sqliteReady := time.Now()
|
||||
maxRetries := 2
|
||||
for i := 0; i < maxRetries; i++ {
|
||||
sqlStore, cleanup, err = getSqlStoreEngine(ctx, store, kind)
|
||||
if err == nil {
|
||||
// Parsed by tools/gotestsummary to attribute store setup time per test.
|
||||
log.WithContext(ctx).Infof("test store created: engine=%s total=%s sqlite=%s engine_setup=%s",
|
||||
kind, time.Since(start).Round(time.Millisecond), sqliteReady.Sub(start).Round(time.Millisecond),
|
||||
time.Since(sqliteReady).Round(time.Millisecond))
|
||||
return sqlStore, cleanup, nil
|
||||
}
|
||||
if i < maxRetries-1 {
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -40,8 +39,6 @@ const (
|
||||
bufferedOutputLines = 400
|
||||
)
|
||||
|
||||
var storeCreatedRe = regexp.MustCompile(`test store created: engine=(\S+) total=(\S+)`)
|
||||
|
||||
type event struct {
|
||||
Action string `json:"Action"`
|
||||
Package string `json:"Package"`
|
||||
@@ -62,11 +59,9 @@ type testKey struct {
|
||||
}
|
||||
|
||||
type testResult struct {
|
||||
pkg, name string
|
||||
action string
|
||||
elapsed time.Duration
|
||||
storeCount int
|
||||
storeTotal time.Duration
|
||||
pkg, name string
|
||||
action string
|
||||
elapsed time.Duration
|
||||
}
|
||||
|
||||
type packageResult struct {
|
||||
@@ -86,7 +81,6 @@ type summarizer struct {
|
||||
// failedBuilds holds the ImportPaths whose build failed and has not been
|
||||
// reported through a package fail event yet.
|
||||
failedBuilds map[string]bool
|
||||
stores map[testKey]storeStats
|
||||
tests []testResult
|
||||
packages []packageResult
|
||||
// panics holds the head of a panic per package. Package streams interleave
|
||||
@@ -95,11 +89,6 @@ type summarizer struct {
|
||||
panics map[string][]string
|
||||
}
|
||||
|
||||
type storeStats struct {
|
||||
count int
|
||||
total time.Duration
|
||||
}
|
||||
|
||||
func newSummarizer(out io.Writer) *summarizer {
|
||||
return &summarizer{
|
||||
out: out,
|
||||
@@ -107,7 +96,6 @@ func newSummarizer(out io.Writer) *summarizer {
|
||||
dropped: make(map[testKey]int),
|
||||
pkgOutput: make(map[string][]string),
|
||||
failedBuilds: make(map[string]bool),
|
||||
stores: make(map[testKey]storeStats),
|
||||
panics: make(map[string][]string),
|
||||
}
|
||||
}
|
||||
@@ -177,7 +165,7 @@ func (s *summarizer) handle(ev event) {
|
||||
s.handleOutput(key, strings.TrimRight(ev.Output, "\n"))
|
||||
case "build-output":
|
||||
// Compiler output may carry several lines per event and is never test
|
||||
// output, so it skips the panic and store-marker detection.
|
||||
// output, so it skips the panic detection.
|
||||
for _, line := range strings.Split(strings.TrimRight(ev.Output, "\n"), "\n") {
|
||||
s.pkgOutput[key.pkg] = appendBounded(s.pkgOutput[key.pkg], line)
|
||||
}
|
||||
@@ -210,15 +198,6 @@ func (s *summarizer) handleOutput(key testKey, line string) {
|
||||
return
|
||||
}
|
||||
|
||||
if m := storeCreatedRe.FindStringSubmatch(line); m != nil {
|
||||
if d, err := time.ParseDuration(m[2]); err == nil {
|
||||
st := s.stores[key]
|
||||
st.count++
|
||||
st.total += d
|
||||
s.stores[key] = st
|
||||
}
|
||||
}
|
||||
|
||||
if key.name == "" {
|
||||
s.pkgOutput[key.pkg] = appendBounded(s.pkgOutput[key.pkg], line)
|
||||
return
|
||||
@@ -239,14 +218,11 @@ func appendBounded(buf []string, line string) []string {
|
||||
|
||||
func (s *summarizer) handleTestResult(key testKey, ev event) {
|
||||
elapsed := time.Duration(ev.Elapsed * float64(time.Second))
|
||||
st := s.stores[key]
|
||||
s.tests = append(s.tests, testResult{
|
||||
pkg: ev.Package,
|
||||
name: ev.Test,
|
||||
action: ev.Action,
|
||||
elapsed: elapsed,
|
||||
storeCount: st.count,
|
||||
storeTotal: st.total,
|
||||
pkg: ev.Package,
|
||||
name: ev.Test,
|
||||
action: ev.Action,
|
||||
elapsed: elapsed,
|
||||
})
|
||||
|
||||
if !strings.Contains(ev.Test, "/") || ev.Action == "fail" {
|
||||
@@ -416,11 +392,7 @@ func (s *summarizer) printSlowest(title string, limit int, keep func(testResult)
|
||||
fmt.Fprintln(s.out)
|
||||
fmt.Fprintf(s.out, "==== %s (%d) ====\n", title, len(tests))
|
||||
for _, t := range tests {
|
||||
line := fmt.Sprintf("%9s %-4s %s.%s", t.elapsed.Round(time.Millisecond), t.action, shortPkg(t.pkg), t.name)
|
||||
if t.storeCount > 0 {
|
||||
line += fmt.Sprintf(" [stores: %d, %s]", t.storeCount, t.storeTotal.Round(time.Millisecond))
|
||||
}
|
||||
fmt.Fprintln(s.out, line)
|
||||
fmt.Fprintf(s.out, "%9s %-4s %s.%s\n", t.elapsed.Round(time.Millisecond), t.action, shortPkg(t.pkg), t.name)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,20 +68,6 @@ func TestPanicInOnePackageKeepsOtherPackageOutput(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreSetupTimeIsAttributedToTheTest(t *testing.T) {
|
||||
events := `
|
||||
{"Action":"run","Package":"a","Test":"TestStore"}
|
||||
{"Action":"output","Package":"a","Test":"TestStore","Output":"level=info msg=\"test store created: engine=mysql total=1.5s sqlite=100ms engine_setup=1.4s\"\n"}
|
||||
{"Action":"output","Package":"a","Test":"TestStore","Output":"level=info msg=\"test store created: engine=mysql total=500ms sqlite=100ms engine_setup=400ms\"\n"}
|
||||
{"Action":"pass","Package":"a","Test":"TestStore","Elapsed":2.5}
|
||||
{"Action":"pass","Package":"a","Elapsed":2.6}
|
||||
`
|
||||
got := feed(t, events)
|
||||
if !strings.Contains(got, "a.TestStore [stores: 2, 2s]") {
|
||||
t.Errorf("store setup not aggregated:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildFailureShowsCompilerOutput(t *testing.T) {
|
||||
// The event sequence go test emits for a build failure: the build events
|
||||
// name the test binary, then the package itself fails with FailedBuild.
|
||||
|
||||
Reference in New Issue
Block a user