From ec82bf357c96bc7b0c91859328f92cb6f1a803fe Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Thu, 3 Apr 2025 10:44:49 +0800 Subject: [PATCH] cmd/workload: add archive flag --- cmd/workload/filtertest.go | 10 +++--- cmd/workload/historytest.go | 44 ++++++----------------- cmd/workload/testsuite.go | 70 +++++++++++++++++++++++++++++++------ cmd/workload/tracetest.go | 6 ++-- 4 files changed, 78 insertions(+), 52 deletions(-) diff --git a/cmd/workload/filtertest.go b/cmd/workload/filtertest.go index 52dd6e41ad..68b8891852 100644 --- a/cmd/workload/filtertest.go +++ b/cmd/workload/filtertest.go @@ -45,11 +45,11 @@ func newFilterTestSuite(cfg testConfig) *filterTestSuite { return s } -func (s *filterTestSuite) allTests() []utesting.Test { - return []utesting.Test{ - {Name: "Filter/ShortRange", Fn: s.filterShortRange}, - {Name: "Filter/LongRange", Fn: s.filterLongRange, Slow: true}, - {Name: "Filter/FullRange", Fn: s.filterFullRange, Slow: true}, +func (s *filterTestSuite) allTests() []workloadTest { + return []workloadTest{ + newWorkLoadTest("Filter/ShortRange", s.filterShortRange), + newSlowWorkloadTest("Filter/LongRange", s.filterLongRange), + newSlowWorkloadTest("Filter/FullRange", s.filterFullRange), } } diff --git a/cmd/workload/historytest.go b/cmd/workload/historytest.go index fc4abe46c1..bfe8989f24 100644 --- a/cmd/workload/historytest.go +++ b/cmd/workload/historytest.go @@ -64,40 +64,16 @@ func (s *historyTestSuite) loadTests() error { return nil } -func (s *historyTestSuite) allTests() []utesting.Test { - return []utesting.Test{ - { - Name: "History/getBlockByHash", - Fn: s.testGetBlockByHash, - }, - { - Name: "History/getBlockByNumber", - Fn: s.testGetBlockByNumber, - }, - { - 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, - }, +func (s *historyTestSuite) allTests() []workloadTest { + return []workloadTest{ + newWorkLoadTest("History/getBlockByHash", s.testGetBlockByHash), + newWorkLoadTest("History/getBlockByNumber", s.testGetBlockByNumber), + newWorkLoadTest("History/getBlockReceiptsByHash", s.testGetBlockReceiptsByHash), + newWorkLoadTest("History/getBlockReceiptsByNumber", s.testGetBlockReceiptsByNumber), + newWorkLoadTest("History/getBlockTransactionCountByHash", s.testGetBlockTransactionCountByHash), + newWorkLoadTest("History/getBlockTransactionCountByNumber", s.testGetBlockTransactionCountByNumber), + newWorkLoadTest("History/getTransactionByBlockHashAndIndex", s.testGetTransactionByBlockHashAndIndex), + newWorkLoadTest("History/getTransactionByBlockNumberAndIndex", s.testGetTransactionByBlockNumberAndIndex), } } diff --git a/cmd/workload/testsuite.go b/cmd/workload/testsuite.go index f66f68fabd..2aa9b0cb11 100644 --- a/cmd/workload/testsuite.go +++ b/cmd/workload/testsuite.go @@ -21,7 +21,6 @@ import ( "fmt" "io/fs" "os" - "slices" "github.com/ethereum/go-ethereum/core/history" "github.com/ethereum/go-ethereum/internal/flags" @@ -45,6 +44,7 @@ var ( testPatternFlag, testTAPFlag, testSlowFlag, + testArchiveFlag, testSepoliaFlag, testMainnetFlag, filterQueryFileFlag, @@ -69,6 +69,12 @@ var ( Value: false, Category: flags.TestingCategory, } + testArchiveFlag = &cli.BoolFlag{ + Name: "archive", + Usage: "Enable archive tests", + Value: false, + Category: flags.TestingCategory, + } testSepoliaFlag = &cli.BoolFlag{ Name: "sepolia", Usage: "Use test cases for sepolia network", @@ -145,6 +151,48 @@ func testConfigFromCLI(ctx *cli.Context) (cfg testConfig) { 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 { cfg := testConfigFromCLI(ctx) filterSuite := newFilterTestSuite(cfg) @@ -155,14 +203,16 @@ func runTestCmd(ctx *cli.Context) error { tests := filterSuite.allTests() tests = append(tests, historySuite.allTests()...) tests = append(tests, traceSuite.allTests()...) - if ctx.IsSet(testPatternFlag.Name) { - tests = utesting.MatchTests(tests, ctx.String(testPatternFlag.Name)) - } - if !ctx.Bool(testSlowFlag.Name) { - tests = slices.DeleteFunc(tests, func(test utesting.Test) bool { - return test.Slow - }) - } + + utests := filterTests(tests, ctx.String(testPatternFlag.Name), func(t workloadTest) bool { + if t.Slow && !ctx.Bool(testSlowFlag.Name) { + return false + } + if t.archive && !ctx.Bool(testArchiveFlag.Name) { + return false + } + return true + }) // Disable logging unless explicitly enabled. if !ctx.IsSet("verbosity") && !ctx.IsSet("vmodule") { @@ -174,7 +224,7 @@ func runTestCmd(ctx *cli.Context) error { if ctx.Bool(testTAPFlag.Name) { run = utesting.RunTAP } - results := run(tests, os.Stdout) + results := run(utests, os.Stdout) if utesting.CountFailures(results) > 0 { os.Exit(1) } diff --git a/cmd/workload/tracetest.go b/cmd/workload/tracetest.go index be85e6c4f2..6e067008ac 100644 --- a/cmd/workload/tracetest.go +++ b/cmd/workload/tracetest.go @@ -72,9 +72,9 @@ func (s *traceTestSuite) loadTests() error { return nil } -func (s *traceTestSuite) allTests() []utesting.Test { - return []utesting.Test{ - {Name: "Trace/Transaction", Fn: s.traceTransaction}, +func (s *traceTestSuite) allTests() []workloadTest { + return []workloadTest{ + newArchiveWorkloadTest("Trace/Transaction", s.traceTransaction), } }