fix(接口测试): 恢复临界控制器修复同名锁问题

This commit is contained in:
fit2-zhao 2022-01-24 17:26:19 +08:00 committed by 刘瑞斌
parent 333c3713d2
commit 2597386377
4 changed files with 23 additions and 3 deletions

View File

@ -8,6 +8,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.metersphere.api.dto.EnvironmentType;
import io.metersphere.api.dto.definition.request.controller.MsCriticalSectionController;
import io.metersphere.api.dto.definition.request.variable.ScenarioVariable;
import io.metersphere.api.dto.mockconfig.MockConfigStaticData;
import io.metersphere.api.dto.scenario.KeyValue;
@ -158,7 +159,10 @@ public class MsScenario extends MsTestElement {
if (CollectionUtils.isNotEmpty(this.getVariables())) {
config.setVariables(this.variables);
}
final HashTree scenarioTree = tree;
HashTree scenarioTree = tree;
if (config != null && !config.getExcludeScenarioIds().contains(this.getId())) {
scenarioTree = MsCriticalSectionController.createHashTree(tree, this.getName());
}
// 场景变量和环境变量
Arguments arguments = arguments(config);
if (arguments != null) {

View File

@ -67,6 +67,10 @@ public class ParameterConfig extends MsParameter {
private String scenarioId;
private String reportType;
/**
* 排除生成临界控制器的场景
*/
private List<String> excludeScenarioIds = new ArrayList<>();
private List<String> csvFilePaths = new ArrayList<>();

View File

@ -8,6 +8,7 @@ import org.apache.jmeter.testelement.TestElement;
import org.apache.jorphan.collections.HashTree;
import java.util.List;
import java.util.UUID;
public class MsCriticalSectionController extends MsTestElement {
@ -18,11 +19,21 @@ public class MsCriticalSectionController extends MsTestElement {
public static HashTree createHashTree(HashTree tree, String name) {
CriticalSectionController criticalSectionController = new CriticalSectionController();
criticalSectionController.setName(StringUtils.isNotEmpty(name) ? "Csc_" + name : "Scenario Critical Section Controller");
criticalSectionController.setLockName("global_lock");
criticalSectionController.setName(StringUtils.isNotEmpty(name) ? "Csc_" + name
: "Scenario Critical Section Controller");
criticalSectionController.setLockName("global_lock_" + getUUID(8));
criticalSectionController.setEnabled(true);
criticalSectionController.setProperty(TestElement.TEST_CLASS, CriticalSectionController.class.getName());
criticalSectionController.setProperty(TestElement.GUI_CLASS, "CriticalSectionControllerGui");
return tree.add(criticalSectionController);
}
public static String getUUID(int len) {
String uuid = UUID.randomUUID().toString();
StringBuffer str = new StringBuffer();
for (int i = 0; i < len; i++) {
str.append(uuid.charAt(i));
}
return str.toString();
}
}

View File

@ -871,6 +871,7 @@ public class ApiAutomationService {
testPlan.setHashTree(new LinkedList<>());
ParameterConfig config = new ParameterConfig();
config.setOperating(true);
config.getExcludeScenarioIds().add(apiScenario.getId());
try {
MsScenario scenario = JSONObject.parseObject(apiScenario.getScenarioDefinition(), MsScenario.class);