需求:
jmeter做接口测试,在云平台创建vm,等vm状态为active后往vm上挂一个卷。
思路:
使用jmeter的while controller实现重试,轮询进行vm状态条件判断。
问题:
jmeter无现成的重试机制,如何实现while controller重试多少次后自动退出?
方案:
1、创建while controller
2、添加查询vm状态的http sampler
3、添加定时器,每隔10s执行一次查询
4、添加beanshell 脚本,记录轮询的次数。
vars.put("waitVMTimes","${__counter(FALSE,Vcount)}");
其中${__counter(FALSE,Vcount)}是jmeter自带的自增函数。每次增加1
5、敲重点,while controller的判断条件:
${__javaScript("${vmstatus}"!="active"&&"${waitVMTimes}"!="5")}
当vm状态为active或重试次数超过5次后就退出while循环。