mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-13 00:11:28 +08:00
fix: avoid data racing.
This commit is contained in:
16
runner.go
16
runner.go
@@ -147,7 +147,7 @@ func (r *caseRunner) run() error {
|
||||
cfg.Variables = mergeVariables(it.Next(), cfg.Variables)
|
||||
r.startTime = time.Now()
|
||||
for index := range r.TestCase.TestSteps {
|
||||
_, err := r.runStep(index)
|
||||
_, err := r.runStep(index, cfg)
|
||||
if err != nil {
|
||||
if r.hrpRunner.failfast {
|
||||
return errors.Wrap(err, "abort running due to failfast setting")
|
||||
@@ -160,8 +160,7 @@ func (r *caseRunner) run() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *caseRunner) runStep(index int) (stepResult *stepData, err error) {
|
||||
config := r.TestCase.Config
|
||||
func (r *caseRunner) runStep(index int, caseConfig *TConfig) (stepResult *stepData, err error) {
|
||||
step := r.TestCase.TestSteps[index]
|
||||
|
||||
// step type priority order: transaction > rendezvous > testcase > request
|
||||
@@ -181,23 +180,18 @@ func (r *caseRunner) runStep(index int) (stepResult *stepData, err error) {
|
||||
log.Error().Err(err).Msg("copy step data failed")
|
||||
return nil, err
|
||||
}
|
||||
copiedConfig := &TConfig{}
|
||||
if err = copier.Copy(copiedConfig, config.ToStruct()); err != nil {
|
||||
log.Error().Err(err).Msg("copy config data failed")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
stepVariables := copiedStep.Variables
|
||||
// override variables
|
||||
// step variables > session variables (extracted variables from previous steps)
|
||||
stepVariables = mergeVariables(stepVariables, r.sessionVariables)
|
||||
// step variables > testcase config variables
|
||||
stepVariables = mergeVariables(stepVariables, copiedConfig.Variables)
|
||||
stepVariables = mergeVariables(stepVariables, caseConfig.Variables)
|
||||
|
||||
// parse step variables
|
||||
parsedVariables, err := parseVariables(stepVariables)
|
||||
if err != nil {
|
||||
log.Error().Interface("variables", copiedConfig.Variables).Err(err).Msg("parse step variables failed")
|
||||
log.Error().Interface("variables", caseConfig.Variables).Err(err).Msg("parse step variables failed")
|
||||
return nil, err
|
||||
}
|
||||
copiedStep.Variables = parsedVariables // avoid data racing
|
||||
@@ -214,7 +208,7 @@ func (r *caseRunner) runStep(index int) (stepResult *stepData, err error) {
|
||||
}
|
||||
} else {
|
||||
// run request
|
||||
copiedStep.Request.URL = buildURL(copiedConfig.BaseURL, copiedStep.Request.URL) // avoid data racing
|
||||
copiedStep.Request.URL = buildURL(caseConfig.BaseURL, copiedStep.Request.URL) // avoid data racing
|
||||
stepResult, err = r.runStepRequest(copiedStep)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("run request step failed")
|
||||
|
||||
Reference in New Issue
Block a user