mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 19:39:44 +08:00
fix: data racing when running boomer
This commit is contained in:
1
go.mod
1
go.mod
@@ -4,6 +4,7 @@ go 1.16
|
||||
|
||||
require (
|
||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||
github.com/jinzhu/copier v0.3.2
|
||||
github.com/jmespath/go-jmespath v0.4.0
|
||||
github.com/maja42/goval v1.2.1
|
||||
github.com/mattn/go-runewidth v0.0.13 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@@ -171,6 +171,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/jinzhu/copier v0.3.2 h1:QdBOCbaouLDYaIPFfi1bKv5F5tPpeTwXe4sD0jqtz5w=
|
||||
github.com/jinzhu/copier v0.3.2/go.mod h1:24xnZezI2Yqac9J61UC6/dG/k76ttpq0DdJI3QmUvro=
|
||||
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
|
||||
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
|
||||
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
|
||||
|
||||
@@ -13,12 +13,6 @@ import (
|
||||
"github.com/httprunner/hrp/builtin"
|
||||
)
|
||||
|
||||
func parseStep(step IStep, config *TConfig) *TStep {
|
||||
tStep := step.ToStruct()
|
||||
tStep.Request.URL = buildURL(config.BaseURL, tStep.Request.URL)
|
||||
return tStep
|
||||
}
|
||||
|
||||
func buildURL(baseURL, stepURL string) string {
|
||||
uConfig, err := url.Parse(baseURL)
|
||||
if err != nil {
|
||||
|
||||
23
runner.go
23
runner.go
@@ -14,6 +14,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -104,9 +105,17 @@ func (r *Runner) runCase(testcase *TestCase) error {
|
||||
func (r *Runner) runStep(step IStep, config *TConfig) (stepData *StepData, err error) {
|
||||
log.Info().Str("step", step.Name()).Msg("run step start")
|
||||
|
||||
// copy step to avoid data racing
|
||||
copiedStep := &TStep{}
|
||||
if err = copier.Copy(copiedStep, step.ToStruct()); err != nil {
|
||||
log.Error().Err(err).Msg("copy step data failed")
|
||||
return
|
||||
}
|
||||
|
||||
stepVariables := copiedStep.Variables
|
||||
// override variables
|
||||
// step variables > session variables (extracted variables from previous steps)
|
||||
stepVariables := mergeVariables(step.ToStruct().Variables, r.sessionVariables)
|
||||
stepVariables = mergeVariables(stepVariables, r.sessionVariables)
|
||||
// step variables > testcase config variables
|
||||
stepVariables = mergeVariables(stepVariables, config.Variables)
|
||||
|
||||
@@ -116,21 +125,21 @@ func (r *Runner) runStep(step IStep, config *TConfig) (stepData *StepData, err e
|
||||
log.Error().Interface("variables", config.Variables).Err(err).Msg("parse step variables failed")
|
||||
return
|
||||
}
|
||||
step.ToStruct().Variables = parsedVariables
|
||||
copiedStep.Variables = parsedVariables // avoid data racing
|
||||
|
||||
if tc, ok := step.(*testcaseWithOptionalArgs); ok {
|
||||
if _, ok := step.(*testcaseWithOptionalArgs); ok {
|
||||
// run referenced testcase
|
||||
log.Info().Str("testcase", tc.step.Name).Msg("run referenced testcase")
|
||||
log.Info().Str("testcase", copiedStep.Name).Msg("run referenced testcase")
|
||||
// TODO: override testcase config
|
||||
stepData, err = r.runStepTestCase(tc.step)
|
||||
stepData, err = r.runStepTestCase(copiedStep)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("run referenced testcase step failed")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// run request
|
||||
tStep := parseStep(step, config)
|
||||
stepData, err = r.runStepRequest(tStep)
|
||||
copiedStep.Request.URL = buildURL(config.BaseURL, copiedStep.Request.URL) // avoid data racing
|
||||
stepData, err = r.runStepRequest(copiedStep)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("run request step failed")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user