mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-09 06:23:52 +08:00
fix: unsafe to write concurrent map and failed to parse parameters(type:[][]interface{}) in testcase script while data driven for testing
This commit is contained in:
@@ -108,7 +108,7 @@ func (b *HRPBoomer) convertBoomerTask(testcase *TestCase, rendezvousList []*Rend
|
|||||||
sessionRunner := caseRunner.newSession()
|
sessionRunner := caseRunner.newSession()
|
||||||
|
|
||||||
if parametersIterator.HasNext() {
|
if parametersIterator.HasNext() {
|
||||||
sessionRunner.updateConfigVariables(parametersIterator.Next())
|
sessionRunner.updateSessionVariables(parametersIterator.Next())
|
||||||
}
|
}
|
||||||
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|||||||
@@ -311,6 +311,10 @@ func convertParameters(key string, parametersRawList interface{}) (parameterSlic
|
|||||||
for i := 0; i < parametersRawSlice.Len(); i++ {
|
for i := 0; i < parametersRawSlice.Len(); i++ {
|
||||||
parametersLine := make(map[string]interface{})
|
parametersLine := make(map[string]interface{})
|
||||||
elem := parametersRawSlice.Index(i)
|
elem := parametersRawSlice.Index(i)
|
||||||
|
// e.g. Type: interface{} | []interface{}, convert interface{} to []interface{}
|
||||||
|
if elem.Kind() == reflect.Interface {
|
||||||
|
elem = elem.Elem()
|
||||||
|
}
|
||||||
switch elem.Kind() {
|
switch elem.Kind() {
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
// case 3
|
// case 3
|
||||||
|
|||||||
@@ -47,6 +47,20 @@ func TestLoadParameters(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
map[string]interface{}{
|
||||||
|
"username-password": []interface{}{
|
||||||
|
[]interface{}{"test1", "111111"},
|
||||||
|
[]interface{}{"test2", "222222"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
map[string]Parameters{
|
||||||
|
"username-password": {
|
||||||
|
{"username": "test1", "password": "111111"},
|
||||||
|
{"username": "test2", "password": "222222"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
nil,
|
nil,
|
||||||
|
|||||||
@@ -52,12 +52,12 @@ func (r *SessionRunner) Start(givenVars map[string]interface{}) error {
|
|||||||
config := r.testCase.Config
|
config := r.testCase.Config
|
||||||
log.Info().Str("testcase", config.Name).Msg("run testcase start")
|
log.Info().Str("testcase", config.Name).Msg("run testcase start")
|
||||||
|
|
||||||
// update config variables with given variables
|
|
||||||
r.updateConfigVariables(givenVars)
|
|
||||||
|
|
||||||
// reset session runner
|
// reset session runner
|
||||||
r.resetSession()
|
r.resetSession()
|
||||||
|
|
||||||
|
// update config variables with given variables
|
||||||
|
r.updateSessionVariables(givenVars)
|
||||||
|
|
||||||
// run step in sequential order
|
// run step in sequential order
|
||||||
for _, step := range r.testCase.TestSteps {
|
for _, step := range r.testCase.TestSteps {
|
||||||
log.Info().Str("step", step.Name()).
|
log.Info().Str("step", step.Name()).
|
||||||
@@ -122,16 +122,16 @@ func (r *SessionRunner) MergeStepVariables(vars map[string]interface{}) (map[str
|
|||||||
return parsedVariables, nil
|
return parsedVariables, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateConfigVariables updates config variables with given variables.
|
// updateSessionVariables updates session variables with given variables.
|
||||||
// this is used for data driven
|
// this is used for data driven
|
||||||
func (r *SessionRunner) updateConfigVariables(parameters map[string]interface{}) {
|
func (r *SessionRunner) updateSessionVariables(parameters map[string]interface{}) {
|
||||||
if len(parameters) == 0 {
|
if len(parameters) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().Interface("parameters", parameters).Msg("update config variables")
|
log.Info().Interface("parameters", parameters).Msg("update session variables")
|
||||||
for k, v := range parameters {
|
for k, v := range parameters {
|
||||||
r.parsedConfig.Variables[k] = v
|
r.sessionVariables[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user