fix(性能测试): 修复性能测试分割csv时重复分割的问题

--bug=1011088 --user=刘瑞斌 【性能测试】github#11235,性能测试:脚本使用CSV分割多节点压测异常,每个节点目前都会从头开始重复取值CSV中的数据,通过数据库错误日志查看,确认同一值被重复多次调用 https://www.tapd.cn/55049933/s/1117039

Closes #11235
This commit is contained in:
CaptainB 2022-03-14 11:14:07 +08:00 committed by 刘瑞斌
parent 4a3937ad00
commit bfa87dc698
2 changed files with 15 additions and 1 deletions

View File

@ -15,6 +15,7 @@ public class EngineContext {
private double[] ratios;
private Map<String, Object> properties = new HashMap<>();
private Map<String, byte[]> testResourceFiles = new HashMap<>();
private Map<String, Boolean> splitFlag = new HashMap<>();
public String getTestId() {
return testId;
@ -108,4 +109,12 @@ public class EngineContext {
public void setTestResourceFiles(Map<String, byte[]> testResourceFiles) {
this.testResourceFiles = testResourceFiles;
}
public Map<String, Boolean> getSplitFlag() {
return splitFlag;
}
public void setSplitFlag(Map<String, Boolean> splitFlag) {
this.splitFlag = splitFlag;
}
}

View File

@ -236,13 +236,17 @@ public class JmeterDocumentParser implements EngineSourceParser {
}
private void splitCsvFile(Node item) {
String filename = item.getText();
// 已经分割过的不再二次分割
if (BooleanUtils.toBoolean(context.getSplitFlag().get(filename))) {
return;
}
Object csvConfig = context.getProperty("csvConfig");
if (csvConfig == null) {
return;
}
double[] ratios = context.getRatios();
int resourceIndex = context.getResourceIndex();
String filename = item.getText();
byte[] content = context.getTestResourceFiles().get(filename);
if (content == null) {
return;
@ -298,6 +302,7 @@ public class JmeterDocumentParser implements EngineSourceParser {
}
// 替换文件
context.getTestResourceFiles().put(filename, csv.toString().getBytes(StandardCharsets.UTF_8));
context.getSplitFlag().put(filename, true);
}
private void processResponseAssertion(Element element) {