feat: record response body length

This commit is contained in:
debugtalk
2021-10-16 15:59:53 +08:00
parent bb292aab8b
commit b1f4a4f006
3 changed files with 13 additions and 9 deletions

View File

@@ -55,11 +55,11 @@ func (b *Boomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
config := &testcase.Config config := &testcase.Config
for _, step := range testcase.TestSteps { for _, step := range testcase.TestSteps {
start := time.Now() start := time.Now()
_, err := runner.runStep(step, config) stepData, err := runner.runStep(step, config)
elapsed := time.Since(start).Nanoseconds() / int64(time.Millisecond) elapsed := time.Since(start).Nanoseconds() / int64(time.Millisecond)
if err == nil { if err == nil {
boomer.RecordSuccess(step.Type(), step.Name(), elapsed, int64(0)) boomer.RecordSuccess(step.Type(), step.Name(), elapsed, stepData.ResponseLength)
} else { } else {
boomer.RecordFailure(step.Type(), step.Name(), elapsed, err.Error()) boomer.RecordFailure(step.Type(), step.Name(), elapsed, err.Error())
} }

View File

@@ -88,7 +88,8 @@ type TestCasePath struct {
type TestCaseSummary struct{} type TestCaseSummary struct{}
type StepData struct { type StepData struct {
Name string // step name Name string // step name
Success bool // step execution result Success bool // step execution result
ExportVars map[string]interface{} // extract variables ResponseLength int64 // response body length
ExportVars map[string]interface{} // extract variables
} }

View File

@@ -100,7 +100,7 @@ func (r *Runner) runCase(testcase *TestCase) error {
} }
func (r *Runner) runStep(step IStep, config *TConfig) (stepData *StepData, err error) { func (r *Runner) runStep(step IStep, config *TConfig) (stepData *StepData, err error) {
log.Printf("run step begin: %v >>>>>>", step.Name()) log.Printf("run step [%v] begin >>>>>>", step.Name())
if tc, ok := step.(*testcaseWithOptionalArgs); ok { if tc, ok := step.(*testcaseWithOptionalArgs); ok {
// run referenced testcase // run referenced testcase
log.Printf("run referenced testcase: %v", tc.step.Name) log.Printf("run referenced testcase: %v", tc.step.Name)
@@ -117,14 +117,16 @@ func (r *Runner) runStep(step IStep, config *TConfig) (stepData *StepData, err e
return return
} }
} }
log.Printf("run step end: %v <<<<<<\n", step.Name()) log.Printf("run step [%v] end, success: %v, responseLength: %v <<<<<<\n",
step.Name(), stepData.Success, stepData.ResponseLength)
return return
} }
func (r *Runner) runStepRequest(step *TStep) (stepData *StepData, err error) { func (r *Runner) runStepRequest(step *TStep) (stepData *StepData, err error) {
stepData = &StepData{ stepData = &StepData{
Name: step.Name, Name: step.Name,
Success: false, Success: false,
ResponseLength: 0,
} }
// prepare request args // prepare request args
@@ -193,6 +195,7 @@ func (r *Runner) runStepRequest(step *TStep) (stepData *StepData, err error) {
} }
stepData.Success = true stepData.Success = true
stepData.ResponseLength = resp.Response().ContentLength
return return
} }