mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 08:19:44 +08:00
feat: record response body length
This commit is contained in:
@@ -55,11 +55,11 @@ func (b *Boomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
|
||||
config := &testcase.Config
|
||||
for _, step := range testcase.TestSteps {
|
||||
start := time.Now()
|
||||
_, err := runner.runStep(step, config)
|
||||
stepData, err := runner.runStep(step, config)
|
||||
elapsed := time.Since(start).Nanoseconds() / int64(time.Millisecond)
|
||||
|
||||
if err == nil {
|
||||
boomer.RecordSuccess(step.Type(), step.Name(), elapsed, int64(0))
|
||||
boomer.RecordSuccess(step.Type(), step.Name(), elapsed, stepData.ResponseLength)
|
||||
} else {
|
||||
boomer.RecordFailure(step.Type(), step.Name(), elapsed, err.Error())
|
||||
}
|
||||
|
||||
@@ -88,7 +88,8 @@ type TestCasePath struct {
|
||||
type TestCaseSummary struct{}
|
||||
|
||||
type StepData struct {
|
||||
Name string // step name
|
||||
Success bool // step execution result
|
||||
ExportVars map[string]interface{} // extract variables
|
||||
Name string // step name
|
||||
Success bool // step execution result
|
||||
ResponseLength int64 // response body length
|
||||
ExportVars map[string]interface{} // extract variables
|
||||
}
|
||||
|
||||
11
runner.go
11
runner.go
@@ -100,7 +100,7 @@ func (r *Runner) runCase(testcase *TestCase) 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 {
|
||||
// run referenced testcase
|
||||
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
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
func (r *Runner) runStepRequest(step *TStep) (stepData *StepData, err error) {
|
||||
stepData = &StepData{
|
||||
Name: step.Name,
|
||||
Success: false,
|
||||
Name: step.Name,
|
||||
Success: false,
|
||||
ResponseLength: 0,
|
||||
}
|
||||
|
||||
// prepare request args
|
||||
@@ -193,6 +195,7 @@ func (r *Runner) runStepRequest(step *TStep) (stepData *StepData, err error) {
|
||||
}
|
||||
|
||||
stepData.Success = true
|
||||
stepData.ResponseLength = resp.Response().ContentLength
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user