Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parallel scenes execution in auto test plan #3166

Merged
merged 3 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion modules/dop/services/autotest_v2/sceneset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
141 changes: 71 additions & 70 deletions modules/dop/services/autotest_v2/testplan_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.RefSetID)),
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
Expand Down