mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-30 21:09:36 +08:00
fix: data racing by parsing config
This commit is contained in:
@@ -55,18 +55,24 @@ func (s *StepTestCaseWithOptionalArgs) Run(r *SessionRunner) (*StepResult, error
|
||||
return stepResult, err
|
||||
}
|
||||
|
||||
// copy step to avoid data racing
|
||||
copiedStep := &TStep{}
|
||||
if err := copier.Copy(copiedStep, s.step); err != nil {
|
||||
log.Error().Err(err).Msg("copy step failed")
|
||||
stepTestCase := s.step.TestCase.(*TestCase)
|
||||
|
||||
// copy testcase to avoid data racing
|
||||
copiedTestCase := &TestCase{}
|
||||
if err := copier.Copy(copiedTestCase, stepTestCase); err != nil {
|
||||
log.Error().Err(err).Msg("copy step testcase failed")
|
||||
return stepResult, err
|
||||
}
|
||||
|
||||
copiedStep.Variables = stepVariables
|
||||
copiedTestCase := copiedStep.TestCase.(*TestCase)
|
||||
|
||||
// override testcase config
|
||||
extendWithTestCase(s.step, copiedTestCase)
|
||||
// override testcase name
|
||||
if s.step.Name != "" {
|
||||
copiedTestCase.Config.Name = s.step.Name
|
||||
}
|
||||
// merge & override variables
|
||||
copiedTestCase.Config.Variables = mergeVariables(stepVariables, copiedTestCase.Config.Variables)
|
||||
// merge & override extractors
|
||||
copiedTestCase.Config.Export = mergeSlices(s.step.Export, copiedTestCase.Config.Export)
|
||||
|
||||
sessionRunner := r.hrpRunner.NewSessionRunner(copiedTestCase)
|
||||
|
||||
@@ -84,11 +90,6 @@ func (s *StepTestCaseWithOptionalArgs) Run(r *SessionRunner) (*StepResult, error
|
||||
stepResult.ExportVars = summary.InOut.ExportVars
|
||||
stepResult.Success = true
|
||||
|
||||
// update extracted variables
|
||||
for k, v := range stepResult.ExportVars {
|
||||
r.sessionVariables[k] = v
|
||||
}
|
||||
|
||||
// merge testcase summary
|
||||
r.summary.Records = append(r.summary.Records, summary.Records...)
|
||||
r.summary.Stat.Total += summary.Stat.Total
|
||||
@@ -97,15 +98,3 @@ func (s *StepTestCaseWithOptionalArgs) Run(r *SessionRunner) (*StepResult, error
|
||||
|
||||
return stepResult, nil
|
||||
}
|
||||
|
||||
// extend referenced testcase with teststep, teststep config merge and override referenced testcase config
|
||||
func extendWithTestCase(testStep *TStep, overriddenTestCase *TestCase) {
|
||||
// override testcase name
|
||||
if testStep.Name != "" {
|
||||
overriddenTestCase.Config.Name = testStep.Name
|
||||
}
|
||||
// merge & override variables
|
||||
overriddenTestCase.Config.Variables = mergeVariables(testStep.Variables, overriddenTestCase.Config.Variables)
|
||||
// merge & override extractors
|
||||
overriddenTestCase.Config.Export = mergeSlices(testStep.Export, overriddenTestCase.Config.Export)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user