Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loadtest: add multi send test #558

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions itest/loadtest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ type Config struct {
// binary.
func DefaultConfig() Config {
return Config{
TestCases: []string{"mint_batch_stress"},
Alice: &User{
Tapd: &TapConfig{
Name: "alice",
Expand All @@ -95,21 +94,11 @@ func DefaultConfig() Config {
//
// The configuration proceeds as follows:
// 1. Start with a default config with sane settings
// 2. Pre-parse the command line to check for an alternative config file
// 3. Load configuration file overwriting defaults with any specified options
// 4. Parse CLI options and overwrite/add any specified options
// 2. Load configuration file overwriting defaults with any specified options
func LoadConfig() (*Config, error) {
// Pre-parse the command line options to pick up an alternative config
// file.
preCfg := DefaultConfig()
if _, err := flags.Parse(&preCfg); err != nil {
return nil, err
}

// Next, load any additional configuration options from the file.
cfg := preCfg
// First, load any additional configuration options from the file.
cfg := DefaultConfig()
fileParser := flags.NewParser(&cfg, flags.Default)

err := flags.NewIniParser(fileParser).ParseFile(defaultConfigPath)
if err != nil {
// If it's a parsing related error, then we'll return
Expand All @@ -120,13 +109,6 @@ func LoadConfig() (*Config, error) {
}
}

// Finally, parse the remaining command line options again to ensure
// they take precedence.
flagParser := flags.NewParser(&cfg, flags.Default)
if _, err := flagParser.Parse(); err != nil {
return nil, err
}

// Make sure everything we just loaded makes sense.
cleanCfg, err := ValidateConfig(cfg)
if err != nil {
Expand Down
61 changes: 47 additions & 14 deletions itest/loadtest/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import (
"github.com/stretchr/testify/require"
)

type testCase struct {
name string
fn func(t *testing.T, ctx context.Context, cfg *Config)
}

var loadTestCases = []testCase{
{
name: "mint_batch_stress",
fn: execMintBatchStressTest,
},
}

// TestPerformance executes the configured performance tests.
func TestPerformance(t *testing.T) {
cfg, err := LoadConfig()
Expand All @@ -18,23 +30,44 @@ func TestPerformance(t *testing.T) {
ctxt, cancel := context.WithTimeout(ctxb, cfg.TestSuiteTimeout)
defer cancel()

for _, testCase := range cfg.TestCases {
execTestCase(t, ctxt, testCase, cfg)
}
}
for _, tc := range loadTestCases {
tc := tc

// execTestCase is the method in charge of executing a single test case.
func execTestCase(t *testing.T, ctx context.Context, testName string,
cfg *Config) {
if !shouldRunCase(tc.name, cfg.TestCases) {
t.Logf("Not running test case '%s' as not configured",
tc.name)

ctxt, cancel := context.WithTimeout(ctx, cfg.TestTimeout)
defer cancel()
continue
}

switch testName {
case "mint_batch_stress":
execMintBatchStressTest(t, ctxt, cfg)
success := t.Run(tc.name, func(tt *testing.T) {
Roasbeef marked this conversation as resolved.
Show resolved Hide resolved
ctxt, cancel := context.WithTimeout(
ctxt, cfg.TestTimeout,
)
defer cancel()

default:
require.Fail(t, "unknown test case: %v", testName)
tc.fn(t, ctxt, cfg)
})
if !success {
t.Fatalf("test case %v failed", tc.name)
}
}
}

// shouldRunCase returns true if the given test case should be run. This will
// return true if the config file does not specify any test cases. In that case
// we can select the test cases to run using the command line
// (-test.run="TestPerformance/test_case_name")
func shouldRunCase(name string, configuredCases []string) bool {
if len(configuredCases) == 0 {
return true
}

for _, c := range configuredCases {
if c == name {
return true
}
}

return false
}