From 688dd363943f3b59c042fc3a6b9aedbfc28d13cc Mon Sep 17 00:00:00 2001 From: debugtalk Date: Tue, 5 Apr 2022 13:41:52 +0800 Subject: [PATCH] fix: panic by data racing --- hrp/step_testcase.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/hrp/step_testcase.go b/hrp/step_testcase.go index ea412058..031133a5 100644 --- a/hrp/step_testcase.go +++ b/hrp/step_testcase.go @@ -44,25 +44,27 @@ func (s *StepTestCaseWithOptionalArgs) Struct() *TStep { } 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{ Name: s.step.Name, StepType: stepTypeTestCase, Success: false, } - testcase := s.step.TestCase.(*TestCase) - // copy testcase to avoid data racing - copiedTestCase := &TestCase{} - if err := copier.Copy(copiedTestCase, testcase); err != nil { - log.Error().Err(err).Msg("copy testcase failed") + stepVariables, err := r.MergeStepVariables(s.step.Variables) + if err != nil { 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 extendWithTestCase(s.step, copiedTestCase)