From 21e28e95628c049a469239af732a4212b61a9fc7 Mon Sep 17 00:00:00 2001 From: shuofan Date: Thu, 25 Nov 2021 13:19:39 +0800 Subject: [PATCH 1/3] Fix parallel scenes execution in auto test plan --- .../dop/services/autotest_v2/testplan_v2.go | 141 +++++++++--------- 1 file changed, 71 insertions(+), 70 deletions(-) diff --git a/modules/dop/services/autotest_v2/testplan_v2.go b/modules/dop/services/autotest_v2/testplan_v2.go index 67856b3fbae..90b4c0f5553 100644 --- a/modules/dop/services/autotest_v2/testplan_v2.go +++ b/modules/dop/services/autotest_v2/testplan_v2.go @@ -612,86 +612,87 @@ func (svc *Service) BatchQuerySceneSetPipelineSnippetYaml(configs []apistructs.S spec.Version = "1.1" scenes := svc.sortAutoTestSceneList(resultsScenes, 1, 10000) - spec.Stages = make([]*pipelineyml.Stage, len(scenes)) - for index, v := range scenes { + sceneGroupMap, groupIDs := getSceneMapByGroupID(scenes) + var stagesValue []*pipelineyml.Stage + for _, groupID := range groupIDs { var specStage pipelineyml.Stage - inputs := v.Inputs - - var params = make(map[string]interface{}) - for _, input := range inputs { - // replace mock random param before return to pipeline - // and so steps can use the same random value - replacedValue := expression.ReplaceRandomParams(input.Value) - params[input.Name] = replacedValue - } - - sceneJson, err := json.Marshal(v) - if err != nil { - return nil, err - } - - if v.RefSetID > 0 { - // scene reference scene set - specStage.Actions = append(specStage.Actions, map[pipelineyml.ActionType]*pipelineyml.Action{ - pipelineyml.Snippet: { - Alias: pipelineyml.ActionAlias(strconv.Itoa(int(v.ID))), - Type: pipelineyml.Snippet, - Labels: map[string]string{ - apistructs.AutotestScene: base64.StdEncoding.EncodeToString(sceneJson), - apistructs.AutotestType: apistructs.AutotestScene, - }, - If: expression.LeftPlaceholder + " 1 == 1 " + expression.RightPlaceholder, - SnippetConfig: &pipelineyml.SnippetConfig{ - Name: apistructs.PipelineSourceAutoTestSceneSet.String() + "-" + strconv.Itoa(int(v.ID)), - Source: apistructs.PipelineSourceAutoTest.String(), + for _, v := range sceneGroupMap[groupID] { + inputs := v.Inputs + + var params = make(map[string]interface{}) + for _, input := range inputs { + // replace mock random param before return to pipeline + // and so steps can use the same random value + replacedValue := expression.ReplaceRandomParams(input.Value) + params[input.Name] = replacedValue + } + + sceneJson, err := json.Marshal(v) + if err != nil { + return nil, err + } + + if v.RefSetID > 0 { + // scene reference scene set + specStage.Actions = append(specStage.Actions, map[pipelineyml.ActionType]*pipelineyml.Action{ + pipelineyml.Snippet: { + Alias: pipelineyml.ActionAlias(strconv.Itoa(int(v.ID))), + Type: pipelineyml.Snippet, Labels: map[string]string{ - apistructs.LabelAutotestExecType: apistructs.SceneSetsAutotestExecType, - apistructs.LabelSceneSetID: strconv.Itoa(int(v.RefSetID)), - apistructs.LabelSpaceID: strconv.Itoa(int(v.SpaceID)), - apistructs.LabelSceneID: strconv.Itoa(int(v.ID)), - //apistructs.LabelIsRefSet: "true", + apistructs.AutotestScene: base64.StdEncoding.EncodeToString(sceneJson), + apistructs.AutotestType: apistructs.AutotestScene, }, + If: expression.LeftPlaceholder + " 1 == 1 " + expression.RightPlaceholder, + SnippetConfig: &pipelineyml.SnippetConfig{ + Name: apistructs.PipelineSourceAutoTestSceneSet.String() + "-" + strconv.Itoa(int(v.ID)), + Source: apistructs.PipelineSourceAutoTest.String(), + Labels: map[string]string{ + apistructs.LabelAutotestExecType: apistructs.SceneSetsAutotestExecType, + apistructs.LabelSceneSetID: strconv.Itoa(int(v.RefSetID)), + apistructs.LabelSpaceID: strconv.Itoa(int(v.SpaceID)), + apistructs.LabelSceneID: strconv.Itoa(int(v.ID)), + //apistructs.LabelIsRefSet: "true", + }, + }, + Policy: &pipelineyml.Policy{Type: v.Policy}, }, - Policy: &pipelineyml.Policy{Type: v.Policy}, - }, - }) - } else { - specStage.Actions = append(specStage.Actions, map[pipelineyml.ActionType]*pipelineyml.Action{ - pipelineyml.Snippet: { - Alias: pipelineyml.ActionAlias(strconv.Itoa(int(v.ID))), - Type: pipelineyml.Snippet, - Params: params, - Labels: map[string]string{ - apistructs.AutotestType: apistructs.AutotestScene, - apistructs.AutotestScene: base64.StdEncoding.EncodeToString(sceneJson), - }, - If: expression.LeftPlaceholder + " 1 == 1 " + expression.RightPlaceholder, - SnippetConfig: &pipelineyml.SnippetConfig{ - Name: strconv.Itoa(int(v.ID)), - Source: apistructs.PipelineSourceAutoTest.String(), + }) + } else { + specStage.Actions = append(specStage.Actions, map[pipelineyml.ActionType]*pipelineyml.Action{ + pipelineyml.Snippet: { + Alias: pipelineyml.ActionAlias(strconv.Itoa(int(v.ID))), + Type: pipelineyml.Snippet, + Params: params, Labels: map[string]string{ - apistructs.LabelAutotestExecType: apistructs.SceneAutotestExecType, - apistructs.LabelSceneID: strconv.Itoa(int(v.ID)), - apistructs.LabelSpaceID: strconv.Itoa(int(v.SpaceID)), - apistructs.LabelIsRefSet: isRefSetMap[key], + apistructs.AutotestType: apistructs.AutotestScene, + apistructs.AutotestScene: base64.StdEncoding.EncodeToString(sceneJson), + }, + If: expression.LeftPlaceholder + " 1 == 1 " + expression.RightPlaceholder, + SnippetConfig: &pipelineyml.SnippetConfig{ + Name: strconv.Itoa(int(v.ID)), + Source: apistructs.PipelineSourceAutoTest.String(), + Labels: map[string]string{ + apistructs.LabelAutotestExecType: apistructs.SceneAutotestExecType, + apistructs.LabelSceneID: strconv.Itoa(int(v.ID)), + apistructs.LabelSpaceID: strconv.Itoa(int(v.SpaceID)), + apistructs.LabelIsRefSet: isRefSetMap[key], + }, }, }, - }, - }) + }) + } } - - spec.Stages[index] = &specStage - } - - for _, v := range scenes { - for _, output := range v.Output { - spec.Outputs = append(spec.Outputs, &pipelineyml.PipelineOutput{ - Name: fmt.Sprintf("%v_%v", v.ID, output.Name), - Ref: fmt.Sprintf("%s %s.%d.%s %s", expression.LeftPlaceholder, expression.Outputs, v.ID, output.Name, expression.RightPlaceholder), - }) + stagesValue = append(stagesValue, &specStage) + for _, v := range sceneGroupMap[groupID] { + for _, output := range v.Output { + spec.Outputs = append(spec.Outputs, &pipelineyml.PipelineOutput{ + Name: fmt.Sprintf("%v_%v", v.ID, output.Name), + Ref: fmt.Sprintf("%s %s.%d.%s %s", expression.LeftPlaceholder, expression.Outputs, v.ID, output.Name, expression.RightPlaceholder), + }) + } } } - + spec.Stages = stagesValue yml, err := pipelineyml.GenerateYml(&spec) if err != nil { return nil, err From fade5b5f754c44ed0d272b934ab33c68da45c8ae Mon Sep 17 00:00:00 2001 From: shuofan Date: Thu, 25 Nov 2021 14:48:03 +0800 Subject: [PATCH 2/3] Fix on click sceneset config --- .../components/auto-test-scenes/leftPage/fileTree/render.go | 2 +- .../fileConfig/scenesSetConfig/scenesStages/operation.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/dop/component-protocol/components/auto-test-scenes/leftPage/fileTree/render.go b/modules/dop/component-protocol/components/auto-test-scenes/leftPage/fileTree/render.go index 1e816b65ef9..73c3c495f32 100644 --- a/modules/dop/component-protocol/components/auto-test-scenes/leftPage/fileTree/render.go +++ b/modules/dop/component-protocol/components/auto-test-scenes/leftPage/fileTree/render.go @@ -120,7 +120,7 @@ func (i *ComponentFileTree) RenderProtocol(c *cptype.Component, g *cptype.Global func (i *ComponentFileTree) onClickFolderTable() error { i.State.IsClickFolderTable = false i.State.IsClickScene = true - id := i.State.ClickFolderTableSceneID + id := i.gsHelper.GetFileTreeSceneID() var req apistructs.AutotestSceneRequest req.SceneID = id diff --git a/modules/dop/component-protocol/components/auto-test-scenes/rightPage/fileDetail/fileConfig/scenesSetConfig/scenesStages/operation.go b/modules/dop/component-protocol/components/auto-test-scenes/rightPage/fileDetail/fileConfig/scenesSetConfig/scenesStages/operation.go index 176a9772065..89e0485c68e 100644 --- a/modules/dop/component-protocol/components/auto-test-scenes/rightPage/fileDetail/fileConfig/scenesSetConfig/scenesStages/operation.go +++ b/modules/dop/component-protocol/components/auto-test-scenes/rightPage/fileDetail/fileConfig/scenesSetConfig/scenesStages/operation.go @@ -345,13 +345,14 @@ func RenderClick(s *SceneStage) error { if err != nil { return err } + s.State.IsClickFolderTableRow = true + s.gsHelper.SetFileTreeSceneID(scene.ID) if scene.RefSetID != 0 { s.gsHelper.SetGlobalSelectedSetID(scene.RefSetID) s.gsHelper.SetFileTreeSceneSetKey(scene.RefSetID) return RenderList(s) } else { s.gsHelper.SetGlobalActiveConfig(gshelper.SceneConfigKey) - s.gsHelper.SetFileTreeSceneID(scene.ID) s.State.SceneID = scene.ID } From 2f05a4cb92052ecc88347cb9b3e08c195c1ed275 Mon Sep 17 00:00:00 2001 From: shuofan Date: Thu, 25 Nov 2021 15:28:43 +0800 Subject: [PATCH 3/3] Fix ref set id --- modules/dop/services/autotest_v2/sceneset.go | 2 +- modules/dop/services/autotest_v2/testplan_v2.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/dop/services/autotest_v2/sceneset.go b/modules/dop/services/autotest_v2/sceneset.go index 38a5af15a3f..6cd652140f8 100644 --- a/modules/dop/services/autotest_v2/sceneset.go +++ b/modules/dop/services/autotest_v2/sceneset.go @@ -172,7 +172,7 @@ func (svc *Service) ExecuteAutotestSceneSet(req apistructs.AutotestExecuteSceneS }, If: expression.LeftPlaceholder + " 1 == 1 " + expression.RightPlaceholder, SnippetConfig: &pipelineyml.SnippetConfig{ - Name: apistructs.PipelineSourceAutoTestSceneSet.String() + "-" + strconv.Itoa(int(v.ID)), + Name: apistructs.PipelineSourceAutoTestSceneSet.String() + "-" + strconv.Itoa(int(v.RefSetID)), Source: apistructs.PipelineSourceAutoTest.String(), Labels: map[string]string{ apistructs.LabelAutotestExecType: apistructs.SceneSetsAutotestExecType, diff --git a/modules/dop/services/autotest_v2/testplan_v2.go b/modules/dop/services/autotest_v2/testplan_v2.go index 90b4c0f5553..3e07d7b1bcf 100644 --- a/modules/dop/services/autotest_v2/testplan_v2.go +++ b/modules/dop/services/autotest_v2/testplan_v2.go @@ -644,7 +644,7 @@ func (svc *Service) BatchQuerySceneSetPipelineSnippetYaml(configs []apistructs.S }, If: expression.LeftPlaceholder + " 1 == 1 " + expression.RightPlaceholder, SnippetConfig: &pipelineyml.SnippetConfig{ - Name: apistructs.PipelineSourceAutoTestSceneSet.String() + "-" + strconv.Itoa(int(v.ID)), + Name: apistructs.PipelineSourceAutoTestSceneSet.String() + "-" + strconv.Itoa(int(v.RefSetID)), Source: apistructs.PipelineSourceAutoTest.String(), Labels: map[string]string{ apistructs.LabelAutotestExecType: apistructs.SceneSetsAutotestExecType,