diff --git a/boomer.go b/boomer.go index 5680137c..93e213ef 100644 --- a/boomer.go +++ b/boomer.go @@ -6,17 +6,25 @@ import ( "github.com/myzhan/boomer" ) +var ( + defaultMasterHost = "127.0.0.1" + defaultMasterPort = 5557 +) + +// run load test with default configs func Boom(testcases ...ITestCase) { - NewBoomer().Run(testcases...) + NewBoomer(defaultMasterHost, defaultMasterPort).Run(testcases...) } -func NewBoomer() *Boomer { +func NewBoomer(masterHost string, masterPort int) *Boomer { return &Boomer{ - debug: false, + Boomer: boomer.NewBoomer(masterHost, masterPort), + debug: false, } } type Boomer struct { + *boomer.Boomer debug bool } diff --git a/boomer_test.go b/boomer_test.go index 2c6645c2..8ce53971 100644 --- a/boomer_test.go +++ b/boomer_test.go @@ -18,5 +18,5 @@ func TestHttpBoomer(t *testing.T) { // }, // } - // Run(testcase1, testcase2) + // Boom(testcase1, testcase2) } diff --git a/cmd/boom.go b/cmd/boom.go new file mode 100644 index 00000000..8803dd1f --- /dev/null +++ b/cmd/boom.go @@ -0,0 +1,54 @@ +package cmd + +import ( + "time" + + "github.com/spf13/cobra" + + "github.com/httprunner/httpboomer" +) + +// boomCmd represents the boom command +var boomCmd = &cobra.Command{ + Use: "boom", + Short: "run load test with boomer", + Long: `run yaml/json testcase files for load test`, + Example: ` $ httpboomer boom demo.json # run specified json testcase file + $ httpboomer boom demo.yaml # run specified yaml testcase file + $ httpboomer boom examples/ # run testcases in specified folder`, + Args: cobra.MinimumNArgs(1), + Run: func(cmd *cobra.Command, args []string) { + var paths []httpboomer.ITestCase + for _, arg := range args { + paths = append(paths, &httpboomer.TestCasePath{Path: arg}) + } + boomer := httpboomer.NewBoomer(masterHost, masterPort) + boomer.EnableCPUProfile(cpuProfile, cpuProfileDuration) + boomer.EnableMemoryProfile(memoryProfile, memoryProfileDuration) + boomer.Run(paths...) + }, +} + +var masterHost string +var masterPort int +var maxRPS int64 // TODO: init boomer with this flag +var requestIncreaseRate string // TODO: init boomer with this flag +var runTasks string // TODO: init boomer with this flag +var memoryProfile string +var memoryProfileDuration time.Duration +var cpuProfile string +var cpuProfileDuration time.Duration + +func init() { + rootCmd.AddCommand(boomCmd) + + 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().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.") + boomCmd.Flags().DurationVar(&cpuProfileDuration, "cpu-profile-duration", 30*time.Second, "CPU profile duration.") +} diff --git a/cmd/run.go b/cmd/run.go index 9f12ada3..12b4cd29 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -12,7 +12,7 @@ import ( var runCmd = &cobra.Command{ Use: "run path...", Short: "run API test", - Long: `run yaml/json testcase files`, + Long: `run yaml/json testcase files for API test`, Example: ` $ httpboomer run demo.json # run specified json testcase file $ httpboomer run demo.yaml # run specified yaml testcase file $ httpboomer run examples/ # run testcases in specified folder`, diff --git a/runner.go b/runner.go index 8ffdbe35..cd8bcd34 100644 --- a/runner.go +++ b/runner.go @@ -8,6 +8,7 @@ import ( "github.com/imroc/req" ) +// run API test with default configs func Run(t *testing.T, testcases ...ITestCase) error { return NewRunner().WithTestingT(t).SetDebug(true).Run(testcases...) }