我正在使用性能插件在Jenkins中运行JMeter作业。如果平均响应时间<1,我需要失败一份工作。 3秒。我在jmeter中看到了“duration assertion”,但它适用于每个线程(每个http请求)。相反,是否可以对每个页面平均进行持续时间断言?
这是我尝试添加BeanSehll Listener和Assertion的方式。
Recording Controller
**Home Page**
BeanShell Listener
Debug Sampler
**Page1**
BeanShell Listener
Debug Sampler
Beanshell Assertion
View Results Tree
答案 0 :(得分:3)
您可以通过某种形式的Beanshell脚本
来实施此检查将以下代码放入Beanshell Listener的“脚本”区域
String requests = vars.get("requests");
String times = vars.get("times");
long requestsSum = 0;
long timesSum = 0;
if (requests != null && times != null) {
log.info("requests: " + requests);
requestsSum = Long.parseLong(vars.get("requests"));
timesSum = Long.parseLong(vars.get("times"));
}
long thisRequest = sampleResult.getTime();
timesSum += thisRequest;
requestsSum++;
vars.put("requests", String.valueOf(requestsSum));
vars.put("times", String.valueOf(timesSum));
long average = timesSum / requestsSum;
if (average > 3000){
sampleResult.setSuccessful(false);
sampleResult.setResponseMessage("Average response time is greater than threshold");
}
上述代码会记录每个请求的响应时间总和以及times
和requests
JMeter Variables
有关Apache JMeter中Beanshell脚本的全面信息,请参阅How to use BeanShell: JMeter's favorite built-in component指南。