From 16347d6796b2491f287d5ec612b10aceccf163dc Mon Sep 17 00:00:00 2001 From: debugtalk Date: Sun, 14 Nov 2021 20:58:45 +0800 Subject: [PATCH] feat: run standalone boomer --- boomer.go | 16 +++------------- boomer_test.go | 2 +- docs/cmd/hrp.md | 2 +- docs/cmd/hrp_boom.md | 6 +++--- docs/cmd/hrp_har2case.md | 2 +- docs/cmd/hrp_run.md | 2 +- hrp/cmd/boom.go | 10 +++++----- 7 files changed, 15 insertions(+), 25 deletions(-) diff --git a/boomer.go b/boomer.go index 37d4100e..d3e25327 100644 --- a/boomer.go +++ b/boomer.go @@ -6,19 +6,9 @@ import ( "github.com/debugtalk/boomer" ) -var ( - defaultMasterHost = "127.0.0.1" - defaultMasterPort = 5557 -) - -// run load test with default configs -func Boom(testcases ...ITestCase) { - NewBoomer(defaultMasterHost, defaultMasterPort).Run(testcases...) -} - -func NewBoomer(masterHost string, masterPort int) *Boomer { +func NewStandaloneBoomer(spawnCount int, spawnRate float64) *Boomer { return &Boomer{ - Boomer: boomer.NewBoomer(masterHost, masterPort), + Boomer: boomer.NewStandaloneBoomer(spawnCount, spawnRate), debug: false, } } @@ -43,7 +33,7 @@ func (b *Boomer) Run(testcases ...ITestCase) { task := b.convertBoomerTask(testcase) taskSlice = append(taskSlice, task) } - boomer.Run(taskSlice...) + b.Boomer.Run(taskSlice...) } func (b *Boomer) convertBoomerTask(testcase *TestCase) *boomer.Task { diff --git a/boomer_test.go b/boomer_test.go index 72fb1c52..2197edd6 100644 --- a/boomer_test.go +++ b/boomer_test.go @@ -18,5 +18,5 @@ func TestHttpBoomer(t *testing.T) { // }, // } - // Boom(testcase1, testcase2) + // NewStandaloneBoomer(1, 1).Run(testcase1, testcase2) } diff --git a/docs/cmd/hrp.md b/docs/cmd/hrp.md index 69efd4da..5d37a378 100644 --- a/docs/cmd/hrp.md +++ b/docs/cmd/hrp.md @@ -22,4 +22,4 @@ Copyright 2021 debugtalk * [hrp har2case](hrp_har2case.md) - Convert HAR to json/yaml testcase files * [hrp run](hrp_run.md) - run API test -###### Auto generated by spf13/cobra on 11-Nov-2021 +###### Auto generated by spf13/cobra on 14-Nov-2021 diff --git a/docs/cmd/hrp_boom.md b/docs/cmd/hrp_boom.md index f2840b48..a3c50706 100644 --- a/docs/cmd/hrp_boom.md +++ b/docs/cmd/hrp_boom.md @@ -24,17 +24,17 @@ hrp boom [flags] --cpu-profile string Enable CPU profiling. --cpu-profile-duration duration CPU profile duration. (default 30s) -h, --help help for boom - --master-host string Host or IP address of locust master for distributed load testing. (default "127.0.0.1") - --master-port int The port to connect to that is used by the locust master for distributed load testing. (default 5557) --max-rps int Max RPS that boomer can generate, disabled by default. --mem-profile string Enable memory profiling. --mem-profile-duration duration Memory profile duration. (default 30s) --request-increase-rate string Request increase rate, disabled by default. (default "-1") --run-tasks string Run tasks without connecting to the master, multiply tasks is separated by comma. Usually, it's for debug purpose. + --spawn-count int The number of users to spawn for load testing (default 1) + --spawn-rate float The rate for spawning users (default 1) ``` ### SEE ALSO * [hrp](hrp.md) - One-stop solution for HTTP(S) testing. -###### Auto generated by spf13/cobra on 11-Nov-2021 +###### Auto generated by spf13/cobra on 14-Nov-2021 diff --git a/docs/cmd/hrp_har2case.md b/docs/cmd/hrp_har2case.md index c9b8baea..550a0016 100644 --- a/docs/cmd/hrp_har2case.md +++ b/docs/cmd/hrp_har2case.md @@ -23,4 +23,4 @@ hrp har2case harPath... [flags] * [hrp](hrp.md) - One-stop solution for HTTP(S) testing. -###### Auto generated by spf13/cobra on 11-Nov-2021 +###### Auto generated by spf13/cobra on 14-Nov-2021 diff --git a/docs/cmd/hrp_run.md b/docs/cmd/hrp_run.md index f580ce58..b2b16817 100644 --- a/docs/cmd/hrp_run.md +++ b/docs/cmd/hrp_run.md @@ -30,4 +30,4 @@ hrp run path... [flags] * [hrp](hrp.md) - One-stop solution for HTTP(S) testing. -###### Auto generated by spf13/cobra on 11-Nov-2021 +###### Auto generated by spf13/cobra on 14-Nov-2021 diff --git a/hrp/cmd/boom.go b/hrp/cmd/boom.go index 118f8083..cf7dd2f4 100644 --- a/hrp/cmd/boom.go +++ b/hrp/cmd/boom.go @@ -22,7 +22,7 @@ var boomCmd = &cobra.Command{ for _, arg := range args { paths = append(paths, &hrp.TestCasePath{Path: arg}) } - boomer := hrp.NewBoomer(masterHost, masterPort) + boomer := hrp.NewStandaloneBoomer(spawnCount, spawnRate) boomer.EnableCPUProfile(cpuProfile, cpuProfileDuration) boomer.EnableMemoryProfile(memoryProfile, memoryProfileDuration) boomer.Run(paths...) @@ -30,8 +30,8 @@ var boomCmd = &cobra.Command{ } var ( - masterHost string - masterPort int + spawnCount int + spawnRate float64 maxRPS int64 // TODO: init boomer with this flag requestIncreaseRate string // TODO: init boomer with this flag runTasks string // TODO: init boomer with this flag @@ -47,8 +47,8 @@ func init() { boomCmd.Flags().Int64Var(&maxRPS, "max-rps", 0, "Max RPS that boomer can generate, disabled by default.") boomCmd.Flags().StringVar(&requestIncreaseRate, "request-increase-rate", "-1", "Request increase rate, disabled by default.") boomCmd.Flags().StringVar(&runTasks, "run-tasks", "", "Run tasks without connecting to the master, multiply tasks is separated by comma. Usually, it's for debug purpose.") - boomCmd.Flags().StringVar(&masterHost, "master-host", "127.0.0.1", "Host or IP address of locust master for distributed load testing.") - boomCmd.Flags().IntVar(&masterPort, "master-port", 5557, "The port to connect to that is used by the locust master for distributed load testing.") + boomCmd.Flags().IntVar(&spawnCount, "spawn-count", 1, "The number of users to spawn for load testing") + boomCmd.Flags().Float64Var(&spawnRate, "spawn-rate", 1, "The rate for spawning users") boomCmd.Flags().StringVar(&memoryProfile, "mem-profile", "", "Enable memory profiling.") boomCmd.Flags().DurationVar(&memoryProfileDuration, "mem-profile-duration", 30*time.Second, "Memory profile duration.") boomCmd.Flags().StringVar(&cpuProfile, "cpu-profile", "", "Enable CPU profiling.")