mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-07 00:39:34 +08:00
fix: deep copy api step to avoid data racing
This commit is contained in:
@@ -2,6 +2,8 @@ package hrp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||||
)
|
)
|
||||||
@@ -95,18 +97,24 @@ func (s *StepAPIWithOptionalArgs) Struct() *TStep {
|
|||||||
return s.step
|
return s.step
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepAPIWithOptionalArgs) Run(r *SessionRunner) (*StepResult, error) {
|
func (s *StepAPIWithOptionalArgs) Run(r *SessionRunner) (stepResult *StepResult, err error) {
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
r.summary.Success = false
|
||||||
|
}
|
||||||
|
stepResult.StepType = stepTypeAPI
|
||||||
|
}()
|
||||||
// extend request with referenced API
|
// extend request with referenced API
|
||||||
api, _ := s.step.API.(*API)
|
api, _ := s.step.API.(*API)
|
||||||
extendWithAPI(s.step, api)
|
step := &TStep{}
|
||||||
|
// deep copy step to avoid data racing
|
||||||
stepResult, err := runStepRequest(r, s.step)
|
if err = copier.Copy(step, s.step); err != nil {
|
||||||
stepResult.StepType = stepTypeAPI
|
log.Error().Err(err).Msg("copy step failed")
|
||||||
if err != nil {
|
return
|
||||||
r.summary.Success = false
|
|
||||||
return stepResult, err
|
|
||||||
}
|
}
|
||||||
return stepResult, nil
|
extendWithAPI(step, api)
|
||||||
|
stepResult, err = runStepRequest(r, step)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// extend teststep with api, teststep will merge and override referenced api
|
// extend teststep with api, teststep will merge and override referenced api
|
||||||
|
|||||||
Reference in New Issue
Block a user