如何将值从线程组传递到 TearDown 线程组?
How to pass values from Thread Group to TearDown Thread Group?
我正在尝试实现 Load Test 测试脚本,该脚本应根据场景执行:
会有几个"producer"线程,通过web服务上传文件到数据库;
会有几个"consumer"线程,它们会下载"producers"上传的文件。
目前,我一直在清理数据库。我可以在发送"producer" 请求后使用JSON 提取器获取记录ID,并使用此ID 来模拟文件下载。但是这个 ID 在 Tear Down 线程组中是不可见的。
你能告诉我,我如何从上传文件的线程组传递值到拆卸线程组吗?
目前,我的 JMeter 4 项目使用具有以下配置的对象:
- 生产者线程组 #1(该线程组上传和下载文件)
- POSTHTTP请求(该请求上传文件)
- JSON 提取器
- 创建变量的名称=id_to_delete
- JSON路径表达式=$.record-id
- 匹配号 = -1
- GET HTTP 请求(此请求下载文件)
- 生产者线程组 #2
- 生产者线程组 #3
- ...
- 拆卸线程组。
JMeter 变量不能在线程组之间共享(包括 TearDown),
您可以将变量值复制到 JMeter 属性 并在 Tear Down 中使用它,例如在 JSR223 Sampler
中
props.put("id_to_delete", vars.get("id_to_delete"));
或使用__setProperty函数将值复制到属性:
${__setProperty(id_to_delete, ${id_to_delete},)}
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.
因此您必须使用 JMeter 属性在线程组之间传递值,例如:
- 设置属性:使用__setProperty()函数
- 要在另一个线程组中获取 属性 值,请使用 __P() function
- 要设置 user-specific (per-thread) 属性 使用 __threadNum() 函数作为后缀 属性 的前缀
示例设置 属性:
${__setProperty(foo_${__threadNum},${YOUR_VARIABLE_HERE})}
示例获取 属性:
${__P(foo_${__threadNum},)}
演示:
更多信息:Knit One Pearl Two: How to Use Variables in Different Thread Groups
我正在尝试实现 Load Test 测试脚本,该脚本应根据场景执行:
会有几个"producer"线程,通过web服务上传文件到数据库;
会有几个"consumer"线程,它们会下载"producers"上传的文件。
目前,我一直在清理数据库。我可以在发送"producer" 请求后使用JSON 提取器获取记录ID,并使用此ID 来模拟文件下载。但是这个 ID 在 Tear Down 线程组中是不可见的。
你能告诉我,我如何从上传文件的线程组传递值到拆卸线程组吗?
目前,我的 JMeter 4 项目使用具有以下配置的对象:
- 生产者线程组 #1(该线程组上传和下载文件)
- POSTHTTP请求(该请求上传文件)
- JSON 提取器
- 创建变量的名称=id_to_delete
- JSON路径表达式=$.record-id
- 匹配号 = -1
- GET HTTP 请求(此请求下载文件)
- 生产者线程组 #2
- 生产者线程组 #3
- ...
- 拆卸线程组。
JMeter 变量不能在线程组之间共享(包括 TearDown),
您可以将变量值复制到 JMeter 属性 并在 Tear Down 中使用它,例如在 JSR223 Sampler
中props.put("id_to_delete", vars.get("id_to_delete"));
或使用__setProperty函数将值复制到属性:
${__setProperty(id_to_delete, ${id_to_delete},)}
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.
因此您必须使用 JMeter 属性在线程组之间传递值,例如:
- 设置属性:使用__setProperty()函数
- 要在另一个线程组中获取 属性 值,请使用 __P() function
- 要设置 user-specific (per-thread) 属性 使用 __threadNum() 函数作为后缀 属性 的前缀
示例设置 属性:
${__setProperty(foo_${__threadNum},${YOUR_VARIABLE_HERE})}
示例获取 属性:
${__P(foo_${__threadNum},)}
演示:
更多信息:Knit One Pearl Two: How to Use Variables in Different Thread Groups