cmd/workload: add archive flag

This commit is contained in:
Gary Rong 2025-04-03 10:44:49 +08:00
parent 2aa44e071a
commit ec82bf357c
4 changed files with 78 additions and 52 deletions

View file

@ -45,11 +45,11 @@ func newFilterTestSuite(cfg testConfig) *filterTestSuite {
return s return s
} }
func (s *filterTestSuite) allTests() []utesting.Test { func (s *filterTestSuite) allTests() []workloadTest {
return []utesting.Test{ return []workloadTest{
{Name: "Filter/ShortRange", Fn: s.filterShortRange}, newWorkLoadTest("Filter/ShortRange", s.filterShortRange),
{Name: "Filter/LongRange", Fn: s.filterLongRange, Slow: true}, newSlowWorkloadTest("Filter/LongRange", s.filterLongRange),
{Name: "Filter/FullRange", Fn: s.filterFullRange, Slow: true}, newSlowWorkloadTest("Filter/FullRange", s.filterFullRange),
} }
} }

View file

@ -64,40 +64,16 @@ func (s *historyTestSuite) loadTests() error {
return nil return nil
} }
func (s *historyTestSuite) allTests() []utesting.Test { func (s *historyTestSuite) allTests() []workloadTest {
return []utesting.Test{ return []workloadTest{
{ newWorkLoadTest("History/getBlockByHash", s.testGetBlockByHash),
Name: "History/getBlockByHash", newWorkLoadTest("History/getBlockByNumber", s.testGetBlockByNumber),
Fn: s.testGetBlockByHash, newWorkLoadTest("History/getBlockReceiptsByHash", s.testGetBlockReceiptsByHash),
}, newWorkLoadTest("History/getBlockReceiptsByNumber", s.testGetBlockReceiptsByNumber),
{ newWorkLoadTest("History/getBlockTransactionCountByHash", s.testGetBlockTransactionCountByHash),
Name: "History/getBlockByNumber", newWorkLoadTest("History/getBlockTransactionCountByNumber", s.testGetBlockTransactionCountByNumber),
Fn: s.testGetBlockByNumber, newWorkLoadTest("History/getTransactionByBlockHashAndIndex", s.testGetTransactionByBlockHashAndIndex),
}, newWorkLoadTest("History/getTransactionByBlockNumberAndIndex", s.testGetTransactionByBlockNumberAndIndex),
{
Name: "History/getBlockReceiptsByHash",
Fn: s.testGetBlockReceiptsByHash,
},
{
Name: "History/getBlockReceiptsByNumber",
Fn: s.testGetBlockReceiptsByNumber,
},
{
Name: "History/getBlockTransactionCountByHash",
Fn: s.testGetBlockTransactionCountByHash,
},
{
Name: "History/getBlockTransactionCountByNumber",
Fn: s.testGetBlockTransactionCountByNumber,
},
{
Name: "History/getTransactionByBlockHashAndIndex",
Fn: s.testGetTransactionByBlockHashAndIndex,
},
{
Name: "History/getTransactionByBlockNumberAndIndex",
Fn: s.testGetTransactionByBlockNumberAndIndex,
},
} }
} }

View file

@ -21,7 +21,6 @@ import (
"fmt" "fmt"
"io/fs" "io/fs"
"os" "os"
"slices"
"github.com/ethereum/go-ethereum/core/history" "github.com/ethereum/go-ethereum/core/history"
"github.com/ethereum/go-ethereum/internal/flags" "github.com/ethereum/go-ethereum/internal/flags"
@ -45,6 +44,7 @@ var (
testPatternFlag, testPatternFlag,
testTAPFlag, testTAPFlag,
testSlowFlag, testSlowFlag,
testArchiveFlag,
testSepoliaFlag, testSepoliaFlag,
testMainnetFlag, testMainnetFlag,
filterQueryFileFlag, filterQueryFileFlag,
@ -69,6 +69,12 @@ var (
Value: false, Value: false,
Category: flags.TestingCategory, Category: flags.TestingCategory,
} }
testArchiveFlag = &cli.BoolFlag{
Name: "archive",
Usage: "Enable archive tests",
Value: false,
Category: flags.TestingCategory,
}
testSepoliaFlag = &cli.BoolFlag{ testSepoliaFlag = &cli.BoolFlag{
Name: "sepolia", Name: "sepolia",
Usage: "Use test cases for sepolia network", Usage: "Use test cases for sepolia network",
@ -145,6 +151,48 @@ func testConfigFromCLI(ctx *cli.Context) (cfg testConfig) {
return cfg return cfg
} }
// workloadTest represents a single test in the workload. It's a wrapper
// of utesting.Test by adding a few additional attributes.
type workloadTest struct {
utesting.Test
archive bool // Flag whether the archive node (full state history) is required for this test
}
func newWorkLoadTest(name string, fn func(t *utesting.T)) workloadTest {
return workloadTest{
Test: utesting.Test{
Name: name,
Fn: fn,
},
}
}
func newSlowWorkloadTest(name string, fn func(t *utesting.T)) workloadTest {
t := newWorkLoadTest(name, fn)
t.Slow = true
return t
}
func newArchiveWorkloadTest(name string, fn func(t *utesting.T)) workloadTest {
t := newWorkLoadTest(name, fn)
t.archive = true
return t
}
func filterTests(tests []workloadTest, pattern string, filterFn func(t workloadTest) bool) []utesting.Test {
var utests []utesting.Test
for _, t := range tests {
if filterFn(t) {
utests = append(utests, t.Test)
}
}
if pattern == "" {
return utests
}
return utesting.MatchTests(utests, pattern)
}
func runTestCmd(ctx *cli.Context) error { func runTestCmd(ctx *cli.Context) error {
cfg := testConfigFromCLI(ctx) cfg := testConfigFromCLI(ctx)
filterSuite := newFilterTestSuite(cfg) filterSuite := newFilterTestSuite(cfg)
@ -155,14 +203,16 @@ func runTestCmd(ctx *cli.Context) error {
tests := filterSuite.allTests() tests := filterSuite.allTests()
tests = append(tests, historySuite.allTests()...) tests = append(tests, historySuite.allTests()...)
tests = append(tests, traceSuite.allTests()...) tests = append(tests, traceSuite.allTests()...)
if ctx.IsSet(testPatternFlag.Name) {
tests = utesting.MatchTests(tests, ctx.String(testPatternFlag.Name)) utests := filterTests(tests, ctx.String(testPatternFlag.Name), func(t workloadTest) bool {
if t.Slow && !ctx.Bool(testSlowFlag.Name) {
return false
} }
if !ctx.Bool(testSlowFlag.Name) { if t.archive && !ctx.Bool(testArchiveFlag.Name) {
tests = slices.DeleteFunc(tests, func(test utesting.Test) bool { return false
return test.Slow }
return true
}) })
}
// Disable logging unless explicitly enabled. // Disable logging unless explicitly enabled.
if !ctx.IsSet("verbosity") && !ctx.IsSet("vmodule") { if !ctx.IsSet("verbosity") && !ctx.IsSet("vmodule") {
@ -174,7 +224,7 @@ func runTestCmd(ctx *cli.Context) error {
if ctx.Bool(testTAPFlag.Name) { if ctx.Bool(testTAPFlag.Name) {
run = utesting.RunTAP run = utesting.RunTAP
} }
results := run(tests, os.Stdout) results := run(utests, os.Stdout)
if utesting.CountFailures(results) > 0 { if utesting.CountFailures(results) > 0 {
os.Exit(1) os.Exit(1)
} }

View file

@ -72,9 +72,9 @@ func (s *traceTestSuite) loadTests() error {
return nil return nil
} }
func (s *traceTestSuite) allTests() []utesting.Test { func (s *traceTestSuite) allTests() []workloadTest {
return []utesting.Test{ return []workloadTest{
{Name: "Trace/Transaction", Fn: s.traceTransaction}, newArchiveWorkloadTest("Trace/Transaction", s.traceTransaction),
} }
} }