jmeter - 我可以在 jmeter 的线程组中的所有线程中使用变量吗?
问题描述
我正在尝试为限速行为创建一个测试计划。我设置了一个规则,在每分钟 X 个请求后阻塞,我想检查我是否得到响应代码 200,直到我达到 X 个请求,然后得到 429。我创建了一个在所有线程之间共享的计数器,但是这似乎是一团糟,因为它不是线程安全的。
这是我的 beanshell“一次唯一的控制器”:
String props_pre_fix = ${section_id} + "-" + ${START.HMS};
props.remove("props_pre_fix" + ${section_id}, props_pre_fix);
props.put("props_pre_fix" + ${section_id}, props_pre_fix);
props.put(props_pre_fix + "_last_response_code", "200");
props.put(props_pre_fix + "_my_counter", "0");
这是 beanshell 断言:
String props_pre_fix = props.get("props_pre_fix" + ${section_id});
//log.info("props_pre_fix " + props_pre_fix);
//extract my counter from props
int my_counter = Integer.parseInt(props.get(props_pre_fix + "_my_counter"));
//extract last response code
String last_response_code = props.get(props_pre_fix + "_last_response_code");
log.info("last_response_code " + last_response_code);
//if last seconds is greater than current seconds it means we are in a new minute - set counter to zero
if(last_response_code.equals("429") && ResponseCode.equals("200")){
log.info("we moved to a new minute - my_counter should be zero");
my_counter = 0;
}
//increase counter
my_counter++;
log.info("set counter with value: " + my_counter);
//save counter
props.put(props_pre_fix + "_my_counter", my_counter + "");
log.info("counter has set with value: " + my_counter);
if (ResponseCode.equals("200")) {
props.put(props_pre_fix + "_last_response_code", "200");
if(my_counter <= ${current_limit}){
Failure = false;
}
else {
Failure = true;
FailureMessage = "leakage of " + (my_counter - ${current_limit}) + " requests";
}
}
else if (ResponseCode.equals("429")) {
props.put(props_pre_fix + "_last_response_code", "429");
if(my_counter > ${current_limit}){
Failure = false;
}
}
我正在使用道具分享柜台,但我显然觉得这不是正确的做法。你能建议我怎么做吗?
解决方案
我认为不可能使用 JMeter 断言自动测试此要求,因为您无法访问当前的吞吐量,所以我宁愿建议考虑交叉检查每秒响应代码和每秒事务图表(可以安装使用JMeter 插件管理器)
所有的200
和429
响应都可以使用如下配置的响应断言标记为成功:
如果出于某种原因您仍想以编程方式执行此操作,您可能需要查看用于在 STDOUT 中显示当前吞吐量的Summariser类源。
推荐阅读
- python - 与 cv2.videocapture() 一起使用时,如何跳过图像序列中丢失的图像/帧?
- python - python3.8中导入pyttsx3发现报错
- c++ - 我需要一个快速搜索的 C++ 列表
- vue.js - 如何在 Element UI 中验证 MIXED INPUT
- c++ - 如何初始化在头文件中声明为 const 的对象?
- c# - 从 WSDL 文件生成 C# 代码时更改枚举命名转换
- flutter - 在 Flutter TableRow 中处理水龙头
- c++ - 用于自动循环填充矩阵
- php - 我想在 php 中找到 RHS = LHS
- angular - Angular - 在组件之间传递数据