cmd/workload: move some more code

This commit is contained in:
Felix Lange 2025-02-25 12:34:35 +01:00
parent 7d542f9e32
commit 33ec53c417
4 changed files with 63 additions and 64 deletions

View file

@ -29,55 +29,30 @@ import (
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/internal/flags"
"github.com/ethereum/go-ethereum/internal/utesting" "github.com/ethereum/go-ethereum/internal/utesting"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
var ( type filterTestSuite struct {
filterCommand = &cli.Command{ ec *ethclient.Client
Name: "filter", filterTest
Usage: "Log filter workload test commands", }
Subcommands: []*cli.Command{
filterGenCommand, func newFilterTestSuite(ctx *cli.Context) *filterTestSuite {
filterPerfCommand, s := &filterTestSuite{ec: makeEthClient(ctx)}
}, s.filterTest.initFilterTest(ctx)
return s
}
func (s *filterTestSuite) allTests() []utesting.Test {
return []utesting.Test{
{Name: "Filter/ShortRange", Fn: s.filterShortRange},
{Name: "Filter/LongRange", Fn: s.filterLongRange},
{Name: "Filter/FullRange", Fn: s.filterFullRange},
} }
filterGenCommand = &cli.Command{ }
Name: "generate",
Usage: "Generates query set for log filter workload test",
ArgsUsage: "<RPC endpoint URL>",
Action: filterGenCmd,
Flags: []cli.Flag{
filterQueryFileFlag,
filterErrorFileFlag,
},
}
filterPerfCommand = &cli.Command{
Name: "performance",
Usage: "Runs log filter performance test against an RPC endpoint",
ArgsUsage: "<RPC endpoint URL>",
Action: filterPerfCmd,
Flags: []cli.Flag{
filterQueryFileFlag,
filterErrorFileFlag,
},
}
filterQueryFileFlag = &cli.StringFlag{
Name: "queries",
Usage: "JSON file containing filter test queries",
Category: flags.TestingCategory,
Value: "filter_queries.json",
}
filterErrorFileFlag = &cli.StringFlag{
Name: "errors",
Usage: "JSON file containing failed filter queries",
Category: flags.TestingCategory,
Value: "filter_errors.json",
}
)
type filterTest struct { type filterTest struct {
filterQueryFile, filterErrorFile string filterQueryFile, filterErrorFile string

View file

@ -28,10 +28,54 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/internal/flags"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
var (
filterCommand = &cli.Command{
Name: "filter",
Usage: "Log filter workload test commands",
Subcommands: []*cli.Command{
filterGenCommand,
filterPerfCommand,
},
}
filterGenCommand = &cli.Command{
Name: "generate",
Usage: "Generates query set for log filter workload test",
ArgsUsage: "<RPC endpoint URL>",
Action: filterGenCmd,
Flags: []cli.Flag{
filterQueryFileFlag,
filterErrorFileFlag,
},
}
filterPerfCommand = &cli.Command{
Name: "performance",
Usage: "Runs log filter performance test against an RPC endpoint",
ArgsUsage: "<RPC endpoint URL>",
Action: filterPerfCmd,
Flags: []cli.Flag{
filterQueryFileFlag,
filterErrorFileFlag,
},
}
filterQueryFileFlag = &cli.StringFlag{
Name: "queries",
Usage: "JSON file containing filter test queries",
Category: flags.TestingCategory,
Value: "filter_queries.json",
}
filterErrorFileFlag = &cli.StringFlag{
Name: "errors",
Usage: "JSON file containing failed filter queries",
Category: flags.TestingCategory,
Value: "filter_errors.json",
}
)
// filterGenCmd is the main function of the filter tests generator. // filterGenCmd is the main function of the filter tests generator.
func filterGenCmd(ctx *cli.Context) error { func filterGenCmd(ctx *cli.Context) error {
f := newFilterTestGen(ctx) f := newFilterTestGen(ctx)

View file

@ -28,7 +28,7 @@ import (
const passCount = 1 const passCount = 1
func filterPerfCmd(ctx *cli.Context) error { func filterPerfCmd(ctx *cli.Context) error {
f := newTestSuite(ctx) f := newFilterTestSuite(ctx)
if f.loadQueries() == 0 { if f.loadQueries() == 0 {
exit("No test requests loaded") exit("No test requests loaded")
} }

View file

@ -19,7 +19,6 @@ package main
import ( import (
"os" "os"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/internal/flags" "github.com/ethereum/go-ethereum/internal/flags"
"github.com/ethereum/go-ethereum/internal/utesting" "github.com/ethereum/go-ethereum/internal/utesting"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
@ -51,27 +50,8 @@ var (
} }
) )
type filterTestSuite struct {
ec *ethclient.Client
filterTest
}
func newTestSuite(ctx *cli.Context) *filterTestSuite {
s := &filterTestSuite{ec: makeEthClient(ctx)}
s.filterTest.initFilterTest(ctx)
return s
}
func (s *filterTestSuite) allTests() []utesting.Test {
return []utesting.Test{
{Name: "Filter/ShortRange", Fn: s.filterShortRange},
{Name: "Filter/LongRange", Fn: s.filterLongRange},
{Name: "Filter/FullRange", Fn: s.filterFullRange},
}
}
func runTestCmd(ctx *cli.Context) error { func runTestCmd(ctx *cli.Context) error {
s := newTestSuite(ctx) s := newFilterTestSuite(ctx)
// Filter test cases. // Filter test cases.
tests := s.allTests() tests := s.allTests()