feat: run standalone boomer

This commit is contained in:
debugtalk
2021-11-14 20:58:45 +08:00
parent e565db32b0
commit 44767169ea
7 changed files with 15 additions and 25 deletions

View File

@@ -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 {

View File

@@ -18,5 +18,5 @@ func TestHttpBoomer(t *testing.T) {
// },
// }
// Boom(testcase1, testcase2)
// NewStandaloneBoomer(1, 1).Run(testcase1, testcase2)
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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.")