Prepare regression testings for kube (#7697)

This commit is contained in:
Giulio rebuffo 2023-06-09 14:38:28 +02:00 committed by GitHub
parent 06af87dad7
commit 614769f7ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 42 deletions

View File

@ -75,7 +75,7 @@ COPY --from=builder /app/build/bin/state /usr/local/bin/state
COPY --from=builder /app/build/bin/txpool /usr/local/bin/txpool COPY --from=builder /app/build/bin/txpool /usr/local/bin/txpool
COPY --from=builder /app/build/bin/verkle /usr/local/bin/verkle COPY --from=builder /app/build/bin/verkle /usr/local/bin/verkle
COPY --from=builder /app/build/bin/caplin-phase1 /usr/local/bin/caplin-phase1 COPY --from=builder /app/build/bin/caplin-phase1 /usr/local/bin/caplin-phase1
COPY --from=builder /app/build/bin/caplin-regression /usr/local/bin/caplin-regression
EXPOSE 8545 \ EXPOSE 8545 \

View File

@ -3,12 +3,14 @@ package main
import ( import (
"flag" "flag"
"net/http" "net/http"
_ "net/http/pprof" //nolint:gosec
"github.com/ledgerwatch/erigon/cl/cltypes" "github.com/ledgerwatch/erigon/cl/cltypes"
"github.com/ledgerwatch/erigon/cl/phase1/forkchoice" "github.com/ledgerwatch/erigon/cl/phase1/forkchoice"
"github.com/ledgerwatch/erigon/cmd/caplin-regression/regression" "github.com/ledgerwatch/erigon/cmd/caplin-regression/regression"
"github.com/ledgerwatch/log/v3" "github.com/ledgerwatch/log/v3"
"golang.org/x/exp/slices"
_ "net/http/pprof" //nolint:gosec
) )
var nameTestsMap = map[string]func(*forkchoice.ForkChoiceStore, *cltypes.SignedBeaconBlock) error{ var nameTestsMap = map[string]func(*forkchoice.ForkChoiceStore, *cltypes.SignedBeaconBlock) error{
@ -17,11 +19,16 @@ var nameTestsMap = map[string]func(*forkchoice.ForkChoiceStore, *cltypes.SignedB
"TestRegressionBadBlocks": regression.TestRegressionBadBlocks, "TestRegressionBadBlocks": regression.TestRegressionBadBlocks,
} }
var excludeTests = []string{"TestRegressionBadBlocks"}
func main() { func main() {
log.Root().SetHandler(log.LvlFilterHandler(log.LvlInfo, log.StderrHandler)) log.Root().SetHandler(log.LvlFilterHandler(log.LvlInfo, log.StderrHandler))
test := flag.String("test", "TestRegressionWithValidation", "select test to run. can be TestRegressionWithValidation, TestRegressionWithoutValidation and TestRegressionBadBlocks") test := flag.String("test", "TestRegressionWithValidation", "select test to run. can be TestRegressionWithValidation, TestRegressionWithoutValidation and TestRegressionBadBlocks")
step := flag.Int("step", 1, "how often to log performance") step := flag.Int("step", 32, "how often to log performance")
pprof := flag.Bool("pprof", true, "turn on profiling") pprof := flag.Bool("pprof", true, "turn on profiling")
loop := flag.Bool("loop", true, "loop the test in an infinite loop")
all := flag.Bool("all", true, "loop trhough all the test")
flag.Parse() flag.Parse()
if _, ok := nameTestsMap[*test]; !ok { if _, ok := nameTestsMap[*test]; !ok {
log.Error("Could not start regression tests", "err", "test not found") log.Error("Could not start regression tests", "err", "test not found")
@ -46,7 +53,20 @@ func main() {
return return
} }
if err := r.Run(*test, nameTestsMap[*test], *step); err != nil { for val := true; val; val = *loop {
log.Error("Could not do regression tests", "err", err) if *all {
for name, t := range nameTestsMap {
if slices.Contains(excludeTests, name) {
continue
}
if err := r.Run(name, t, *step); err != nil {
log.Error("Could not do regression tests", "err", err)
}
}
continue
}
if err := r.Run(*test, nameTestsMap[*test], *step); err != nil {
log.Error("Could not do regression tests", "err", err)
}
} }
} }

View File

@ -34,44 +34,43 @@ func NewRegressionTester(testDirectory string) (*RegressionTester, error) {
} }
func (r *RegressionTester) Run(name string, fn func(*forkchoice.ForkChoiceStore, *cltypes.SignedBeaconBlock) error, step int) error { func (r *RegressionTester) Run(name string, fn func(*forkchoice.ForkChoiceStore, *cltypes.SignedBeaconBlock) error, step int) error {
for true { state, err := r.readStartingState()
state, err := r.readStartingState() if err != nil {
if err != nil { return err
return err
}
store, err := forkchoice.NewForkChoiceStore(state, nil, nil, true)
if err != nil {
return err
}
log.Info("Loading public keys into memory")
bls.SetEnabledCaching(true)
state.ForEachValidator(func(v solid.Validator, idx, total int) bool {
pk := v.PublicKey()
if err := bls.LoadPublicKeyIntoCache(pk[:], false); err != nil {
panic(err)
}
return true
})
store.OnTick(uint64(time.Now().Unix()))
begin := time.Now()
beginStep := time.Now()
log.Info("Starting test, CTRL+C to stop.", "name", name)
for _, block := range r.blockList {
if err := fn(store, block); err != nil {
return err
}
if block.Block.Slot%uint64(step) == 0 {
elapsed := time.Since(beginStep)
log.Info("Processed", "slot", block.Block.Slot, "elapsed", elapsed, "sec/blk", elapsed/time.Duration(step))
beginStep = time.Now()
}
}
var m runtime.MemStats
dbg.ReadMemStats(&m)
sum := time.Since(begin)
log.Info("Finished/Restarting test", "name", name, "averageBlockTime", sum/time.Duration(len(r.blockList)), "sys", common.ByteCount(m.Sys))
} }
store, err := forkchoice.NewForkChoiceStore(state, nil, nil, true)
if err != nil {
return err
}
log.Info("Loading public keys into memory")
bls.SetEnabledCaching(true)
state.ForEachValidator(func(v solid.Validator, idx, total int) bool {
pk := v.PublicKey()
if err := bls.LoadPublicKeyIntoCache(pk[:], false); err != nil {
panic(err)
}
return true
})
store.OnTick(uint64(time.Now().Unix()))
begin := time.Now()
beginStep := time.Now()
log.Info("Starting test, CTRL+C to stop.", "name", name)
for _, block := range r.blockList {
if err := fn(store, block); err != nil {
return err
}
if block.Block.Slot%uint64(step) == 0 {
elapsed := time.Since(beginStep)
log.Info("Processed", "slot", block.Block.Slot, "elapsed", elapsed, "sec/blk", elapsed/time.Duration(step))
beginStep = time.Now()
}
}
var m runtime.MemStats
dbg.ReadMemStats(&m)
sum := time.Since(begin)
log.Info("Finished/Restarting test", "name", name, "averageBlockTime", sum/time.Duration(len(r.blockList)), "sys", common.ByteCount(m.Sys))
return nil return nil
} }