mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +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()
|
||||
|
||||
if parametersIterator.HasNext() {
|
||||
sessionRunner.updateConfigVariables(parametersIterator.Next())
|
||||
sessionRunner.updateSessionVariables(parametersIterator.Next())
|
||||
}
|
||||
|
||||
startTime := time.Now()
|
||||
|
||||
@@ -311,6 +311,10 @@ func convertParameters(key string, parametersRawList interface{}) (parameterSlic
|
||||
for i := 0; i < parametersRawSlice.Len(); i++ {
|
||||
parametersLine := make(map[string]interface{})
|
||||
elem := parametersRawSlice.Index(i)
|
||||
// e.g. Type: interface{} | []interface{}, convert interface{} to []interface{}
|
||||
if elem.Kind() == reflect.Interface {
|
||||
elem = elem.Elem()
|
||||
}
|
||||
switch elem.Kind() {
|
||||
case reflect.Slice:
|
||||
// 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{}{},
|
||||
nil,
|
||||
|
||||
@@ -52,12 +52,12 @@ func (r *SessionRunner) Start(givenVars map[string]interface{}) error {
|
||||
config := r.testCase.Config
|
||||
log.Info().Str("testcase", config.Name).Msg("run testcase start")
|
||||
|
||||
// update config variables with given variables
|
||||
r.updateConfigVariables(givenVars)
|
||||
|
||||
// reset session runner
|
||||
r.resetSession()
|
||||
|
||||
// update config variables with given variables
|
||||
r.updateSessionVariables(givenVars)
|
||||
|
||||
// run step in sequential order
|
||||
for _, step := range r.testCase.TestSteps {
|
||||
log.Info().Str("step", step.Name()).
|
||||
@@ -122,16 +122,16 @@ func (r *SessionRunner) MergeStepVariables(vars map[string]interface{}) (map[str
|
||||
return parsedVariables, nil
|
||||
}
|
||||
|
||||
// updateConfigVariables updates config variables with given variables.
|
||||
// updateSessionVariables updates session variables with given variables.
|
||||
// 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 {
|
||||
return
|
||||
}
|
||||
|
||||
log.Info().Interface("parameters", parameters).Msg("update config variables")
|
||||
log.Info().Interface("parameters", parameters).Msg("update session variables")
|
||||
for k, v := range parameters {
|
||||
r.parsedConfig.Variables[k] = v
|
||||
r.sessionVariables[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user