【问题标题】:jmeter ${__threadNum} does not render when passed through command line argumentjmeter ${__threadNum} 通过命令行参数传递时不呈现
【发布时间】:2018-07-17 21:38:37
【问题描述】:

我正在设置一个 jmeter 负载测试,每个模拟用户都将提交对他们自己独特内容源的引用。出于这个原因,在每次测试开始时,我都会创建一个新的文件夹结构,其中的路径包含对每个模拟用户的数字引用。

该数字计划对应于 jmeter ${__threadNum} 值。

测试运行后,每个模拟用户都会向 API 端点发送一个 POST 请求,其中请求的主体将包含任何给定用户目录中每个文件的绝对路径。

示例: 如果测试模拟两个用户,我将创建以下文件夹结构:

/storage
  /testfiles_user1
    test_file_1
    test_file_2
  /testfiles_user2
    test_file_1
    test_file_2

那么对于每个用户,POST 请求的请求正文中将包含以下 JSON

对于用户 1:

{
  "files": [
             "/storage/testfiles_user1/test_file_1",
             "/storage/testfiles_user1/test_file_2"
           ]
}

对于用户 2:

{
  "files": [
             "/storage/testfiles_user2/test_file_1",
             "/storage/testfiles_user2/test_file_2"
           ]
}

我的问题来了。

当我在 HTTP 请求正文中硬编码此路径时,调用 ${__threadNum},以下列方式

{
  "files": [
             "/storage/testfiles_user${__threadNum}/test_file_1",
             "/storage/testfiles_user${__threadNum}/test_file_2"
           ]
}

然后一切都按预期工作 => 使用 ${__threadNum} 变量值更新路径,生成以下两个 JSON

对于用户 1:

{
  "files": [
             "/storage/testfiles_user1/test_file_1",
             "/storage/testfiles_user1/test_file_2"
           ]
}

对于用户 2:

{
  "files": [
             "/storage/testfiles_user2/test_file_1",
             "/storage/testfiles_user2/test_file_2"
           ]
}

但是,当我尝试将 HTTP 请求正文 JSON 作为命令行参数传递时,${__threadNum} 在路径中呈现为普通文本,jmeter 不将其视为变量,从而产生以下两个 JSON: 对于用户 1:

{
  "files": [
             "/storage/testfiles_user${__threadNum}/test_file_1",
             "/storage/testfiles_user${__threadNum}/test_file_2"
           ]
}

对于用户 2:

{
  "files": [
             "/storage/testfiles_user${__threadNum}/test_file_1",
             "/storage/testfiles_user${__threadNum}/test_file_2"
           ]
}

您对如何解决这个问题有什么建议吗?感谢您的帮助!

【问题讨论】:

    标签: jmeter performance-testing load-testing jmeter-4.0


    【解决方案1】:

    为了解析文件中的 JMeter 变量或通过命令行参数传递,您需要将调用包装到 __eval() function

    例如,如果您之前有 ${__P(foo,)},则需要将其替换为 ${__eval(${__P(foo,)})} - 这样嵌套的 __threadNum() function 将被调用。

    演示:

    更多信息:Here’s What to Do to Combine Multiple JMeter Variables

    【讨论】:

      猜你喜欢
      • 2014-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-13
      • 2021-11-29
      相关资源
      最近更新 更多