fix(测试计划): 修复多个测试计划关联同一个场景并发执行证书偶尔获取不到问题

Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
fit2-zhao 2024-01-22 19:34:53 +08:00 committed by Craftsman
parent ebe66238a1
commit 352e466a30
8 changed files with 14 additions and 5 deletions

View File

@ -91,6 +91,7 @@ public class MsScenario extends MsTestElement {
HashTree scenarioTree = tree;
// 取出自身场景环境
ParameterConfig newConfig = new ParameterConfig(this.getProjectId(), false);
newConfig.setReportId(config.getReportId());
if (this.isEnvironmentEnable()) {
this.setNewConfig(newConfig);
newConfig.setRetryNum(config.getRetryNum());

View File

@ -136,6 +136,9 @@ public class MsHTTPSamplerProxy extends MsTestElement {
sampler.setProperty(TestElement.TEST_CLASS, HTTPSamplerProxy.class.getName());
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("HttpTestSampleGui"));
String resourceId = ElementUtil.setBaseParams(sampler, this.getParent(), config, this.getId(), this.getIndex());
resourceId = StringUtils.isNotBlank(config.getReportId()) ? config.getReportId() : resourceId;
LogUtil.info("设置SSL证书配置{}", resourceId);
sampler.setProperty("MS-KEYSTORE-ID", resourceId);
sampler.setMethod(this.getMethod());
sampler.setContentEncoding(StandardCharsets.UTF_8.name());
@ -551,7 +554,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
keystoreConfig.setProperty("startIndex", 0);
keystoreConfig.setProperty(ElementConstants.MS_KEYSTORE_FILE_PATH, msKeyStore.getPath());
keystoreConfig.setProperty(ElementConstants.MS_KEYSTORE_FILE_PASSWORD, msKeyStore.getPassword());
keystoreConfig.setProperty("MS-RESOURCE-ID", resourceId);
keystoreConfig.setProperty("MS-KEYSTORE-ID", resourceId);
httpSamplerTree.add(keystoreConfig);
config.getKeyStoreMap().put(this.getProjectId(), new MsKeyStore(msKeyStore.getPath(), msKeyStore.getPassword()));
}

View File

@ -140,6 +140,7 @@ public class ApiCaseSerialService {
if (runRequest.isRetryEnable() && runRequest.getRetryNum() > 0) {
config.setRetryNum(runRequest.getRetryNum());
}
config.setReportId(runRequest.getReportId());
testPlan.toHashTree(jmeterHashTree, testPlan.getHashTree(), config);
LoggerUtil.info("用例资源:" + caseWithBLOBs.getName() + ", 生成执行脚本JMX成功", runRequest.getReportId());
return jmeterHashTree;

View File

@ -442,6 +442,7 @@ public class ApiScenarioExecuteService {
}
ParameterConfig config = new ParameterConfig(request.getProjectId(), false);
config.setScenarioId(request.getScenarioId());
config.setReportId(request.getReportId());
if (MapUtils.isNotEmpty(request.getEnvironmentMap())) {
apiScenarioEnvService.setEnvConfig(request.getEnvironmentMap(), config);
}

View File

@ -157,6 +157,8 @@ public class GenerateHashTreeUtil {
config.setScenarioId(item.getId());
config.setReportType(runRequest.getReportType());
config.setConfig(getEnv(scenario.getEnvironmentMap()));
config.setReportId(runRequest.getReportId());
if (runRequest.isRetryEnable() && runRequest.getRetryNum() > 0) {
config.setRetryNum(runRequest.getRetryNum());
}

View File

@ -124,6 +124,7 @@ public class ApiJMeterFileService {
JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(remoteTestId, reportId, runMode, null);
runRequest.setReportType(reportType);
runRequest.setQueueId(queueId);
runRequest.setReportId(reportId);
BooleanPool booleanPool = new BooleanPool();
booleanPool.setK8s(true);
runRequest.setPool(booleanPool);

View File

@ -56,7 +56,7 @@ public class KeystoreConfig extends ConfigTestElement implements TestBean, TestS
@Override
public void testEnded(String host) {
log.info("Destroying Keystore");
String resourceId = this.getPropertyAsString("MS-RESOURCE-ID");
String resourceId = this.getPropertyAsString("MS-KEYSTORE-ID");
SSLManager.getInstance().destroyKeystore(resourceId);
}
@ -101,7 +101,7 @@ public class KeystoreConfig extends ConfigTestElement implements TestBean, TestS
String path = this.getPropertyAsString("MS-KEYSTORE-FILE-PATH");
String password = this.getPropertyAsString("MS-KEYSTORE-FILE-PASSWORD");
// 获取请求上的资源ID
String resourceId = this.getPropertyAsString("MS-RESOURCE-ID");
String resourceId = this.getPropertyAsString("MS-KEYSTORE-ID");
if (StringUtils.isNotBlank(resourceId)) {
KeystoreDTO dto = new KeystoreDTO();
dto.setStartIndex(startIndexAsInt);

View File

@ -150,7 +150,7 @@ public abstract class SSLManager {
// 重新加载认证文件
JMeterContext threadContext = JMeterContextService.getContext();
if (threadContext != null && threadContext.getCurrentSampler() != null) {
String resourceId = threadContext.getCurrentSampler().getPropertyAsString("MS-RESOURCE-ID");
String resourceId = threadContext.getCurrentSampler().getPropertyAsString("MS-KEYSTORE-ID");
if (StringUtils.isNotBlank(resourceId) && keyMap.containsKey(resourceId)) {
log.info("重新加载认证文件{}", resourceId);
KeystoreDTO dto = keyMap.get(resourceId);
@ -371,7 +371,7 @@ public abstract class SSLManager {
// 重新加载认证文件
JMeterContext threadContext = JMeterContextService.getContext();
if (threadContext != null && threadContext.getCurrentSampler() != null) {
String resourceId = threadContext.getCurrentSampler().getPropertyAsString("MS-RESOURCE-ID");
String resourceId = threadContext.getCurrentSampler().getPropertyAsString("MS-KEYSTORE-ID");
if (StringUtils.isNotBlank(resourceId) && keyMap.containsKey(resourceId)) {
log.info("重新加载认证文件{}", resourceId);
KeystoreDTO dto = keyMap.get(resourceId);