mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-10 06:51:44 +08:00
change: make API more concise
This commit is contained in:
21
boomer.go
21
boomer.go
@@ -8,25 +8,27 @@ import (
|
||||
"github.com/httprunner/hrp/internal/ga"
|
||||
)
|
||||
|
||||
func NewStandaloneBoomer(spawnCount int, spawnRate float64) *Boomer {
|
||||
b := &Boomer{
|
||||
func NewStandaloneBoomer(spawnCount int, spawnRate float64) *hrpBoomer {
|
||||
b := &hrpBoomer{
|
||||
Boomer: boomer.NewStandaloneBoomer(spawnCount, spawnRate),
|
||||
debug: false,
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
type Boomer struct {
|
||||
type hrpBoomer struct {
|
||||
*boomer.Boomer
|
||||
debug bool
|
||||
}
|
||||
|
||||
func (b *Boomer) SetDebug(debug bool) *Boomer {
|
||||
// SetDebug configures whether to log HTTP request and response content.
|
||||
func (b *hrpBoomer) SetDebug(debug bool) *hrpBoomer {
|
||||
b.debug = debug
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *Boomer) Run(testcases ...ITestCase) {
|
||||
// Run starts to run load test for one or multiple testcases.
|
||||
func (b *hrpBoomer) Run(testcases ...ITestCase) {
|
||||
event := ga.EventTracking{
|
||||
Category: "RunLoadTests",
|
||||
Action: "hrp boom",
|
||||
@@ -48,11 +50,12 @@ func (b *Boomer) Run(testcases ...ITestCase) {
|
||||
b.Boomer.Run(taskSlice...)
|
||||
}
|
||||
|
||||
func (b *Boomer) Quit() {
|
||||
// Quit stops running load test.
|
||||
func (b *hrpBoomer) Quit() {
|
||||
b.Boomer.Quit()
|
||||
}
|
||||
|
||||
func (b *Boomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
|
||||
func (b *hrpBoomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
|
||||
return &boomer.Task{
|
||||
Name: testcase.Config.Name,
|
||||
Weight: testcase.Config.Weight,
|
||||
@@ -65,9 +68,9 @@ func (b *Boomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
|
||||
stepData, err := runner.runStep(step, config)
|
||||
elapsed := time.Since(start).Nanoseconds() / int64(time.Millisecond)
|
||||
if err == nil {
|
||||
b.RecordSuccess(step.getType(), step.name(), elapsed, stepData.responseLength)
|
||||
b.RecordSuccess(step.Type(), step.Name(), elapsed, stepData.responseLength)
|
||||
} else {
|
||||
b.RecordFailure(step.getType(), step.name(), elapsed, err.Error())
|
||||
b.RecordFailure(step.Type(), step.Name(), elapsed, err.Error())
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user