fix: panic by data racing

This commit is contained in:
debugtalk
2022-04-05 13:41:52 +08:00
parent 19695e76ff
commit 688dd36394

View File

@@ -44,25 +44,27 @@ func (s *StepTestCaseWithOptionalArgs) Struct() *TStep {
} }
func (s *StepTestCaseWithOptionalArgs) Run(r *SessionRunner) (*StepResult, error) { func (s *StepTestCaseWithOptionalArgs) Run(r *SessionRunner) (*StepResult, error) {
stepVariables, err := r.MergeStepVariables(s.step.Variables)
if err != nil {
return nil, err
}
s.step.Variables = stepVariables
stepResult := &StepResult{ stepResult := &StepResult{
Name: s.step.Name, Name: s.step.Name,
StepType: stepTypeTestCase, StepType: stepTypeTestCase,
Success: false, Success: false,
} }
testcase := s.step.TestCase.(*TestCase)
// copy testcase to avoid data racing stepVariables, err := r.MergeStepVariables(s.step.Variables)
copiedTestCase := &TestCase{} if err != nil {
if err := copier.Copy(copiedTestCase, testcase); err != nil {
log.Error().Err(err).Msg("copy testcase failed")
return stepResult, err 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")
return stepResult, err
}
copiedStep.Variables = stepVariables
copiedTestCase := copiedStep.TestCase.(*TestCase)
// override testcase config // override testcase config
extendWithTestCase(s.step, copiedTestCase) extendWithTestCase(s.step, copiedTestCase)