当前位置:网站首页>How to stop the test after reaching a given number of errors during stress testing in JMeter
How to stop the test after reaching a given number of errors during stress testing in JMeter
2022-08-09 20:46:00 【xuechao】
问题
When doing interface automation performance testing,Occasionally there are unstable factors that cause the request assertion to fail.JMeterThread groups have two common ways of handling errors:Continue or stop the test

For some reasons, very few errors do not affect the pressure measurement results and can be ignored,If choose to continue the test,It also keeps going down when a service crash does happen, which is not what we want,So how can we stop the test after reaching the specified cumulative number of errors during the stress test??
解决方案
大致思路:使用beanshellThe script uses the variable after each requestcount记录错误数,Pass after reaching a predetermined number of errorsctx调用stopTest()结束测试.
setUp Thread Group中添加一个BeanShell Sampler
image-20220507113449876 Add to test planBeanShell Listener
image-20220507113632198 执行测试
image-20220507115518016 以上使用httpbinProvided interface for testing,The request address does not exist/error,So in accumulating the number of errorscount=5The test stops when.
BeanShell Code
// BeanShell Sampler
props.put("__count", "0");
// BeanShell Listener
int __count = Integer.parseInt(props.get("__count"));
int __limit = 5;
int responseCode;
try {
responseCode = Integer.parseInt(prev.getResponseCode());
}
catch (exception ex) {
responseCode = 0;
}
boolean errorResponse = ((responseCode < 200) || (responseCode >= 400) || (prev.getErrorCount() > 0) || (prev.getFirstAssertionFailureMessage() != null));
if (errorResponse) {
__count = __count + 1;
}
log.warn( "errors = " + __count );
if (__count >= __limit) {
log.warn("maximum number of errors reached, aborting test.");
ctx.getEngine().stopTest();
}
props.put("__count", String.valueOf(__count));
讨论
in the overall solution,用到了JMeter的一些特性:
props设置countvariable is initialized only once,Accumulate later,这里用了setUp Group; 为什么使用BeanShell Listener:在errorResponseThere is a response to the judgment condition ofcode、Number of errors and assertion information,These are only available after the assertion completes,按照JMeter组件执行顺序,ListenerComponents meet the conditions of use;
边栏推荐
猜你喜欢
C语言知识补充
Engaged in software testing for a year, only basic functional testing, how to further study?
2022 全球 AI 模型周报
100+开箱即用的AI工具箱;程序员150岁长寿指南;『地理空间数据科学』课程资料;Graphic数据可视化图表库;前沿论文 | ShowMeAI资讯日报
艺术与科技的狂欢,云端XR支撑阿那亚2022砂之盒沉浸艺术季
日本著名设计师三宅一生去世:产品曾被国人高价抢 乔布斯也是粉丝
numpy中nan_to_num如何使用
Metasploit——辅助模块(Auxiliary)
动手学深度学习_全卷积网络 FCN
ARM 汇编基础
随机推荐
毕昇编译器优化:Lazy Code Motion
解决启动项目初始化报错required a bean of type ‘int‘ that could not be found.的问题
.NET现代应用的产品设计 - DDD实践
How to play with container local storage through open-local? | Dragon Lizard Technology
Flink on Yarn
不是吧,连公司里的卷王写代码都复制粘贴,这合理?
win10 uwp 模拟网页输入
Flink运行架构
InfluxDB语法
ceph集群部署
说了半天跨平台,今儿咱就来跨跨!(完结篇)——Kubenetes上手实践
什么是ROS
What are some good open source automation testing frameworks to recommend?
集合框架Collection与Map的区别和基本使用
winpe工具WEPE微PE工具箱
JMeter压测时如何在达到给定错误数量后停止测试
win10 uwp 简单MasterDetail
史上最全架构师知识图谱(纯干货)
Volatile: JVM I warn you, my people don't move
日本著名设计师三宅一生去世:产品曾被国人高价抢 乔布斯也是粉丝