JMeter - 为什么一次只有控制器运行多次 [英] JMeter - Why once only controller runs more than once

查看:24
本文介绍了JMeter - 为什么一次只有控制器运行多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了两个请求,一个用于登录以存储会话 ID,另一个请求用于检查需要会话 ID 的负载测试.

I added two request one for login to store the session id and another request to check the load test which requires session id.

我只发出一次登录请求,将其添加为一个子控制器.

I made login request as once only, by adding it as a child for once only controller.

但是当我通过添加大约 100 或 200 个线程来测试它时,登录也运行了那么多时间.我只想为启动线程运行登录请求.是否可以?下面我添加了我的测试用例层次结构.

But when I test it by adding about 100 or 200 thread the login is also running that much of time. I want to run login request for only starting thread. Is it possible? Below I added my test case hierarchy.

 ThreadGroup: 
 HTTP request default 
 HTTP cookie manager
     once only controller
 login HTTP request
 HTTP request for number of users 

推荐答案

ONLY ONCE"控制器与您想象的不一样.

The "ONLY ONCE" controller doesn't work the way you think it does.

它每个线程只运行一次".因此,如果您有 100 个线程,它将运行 100 次.

It runs "only once" PER THREAD. Thus, if you have 100 threads, it will run 100 times.

如果您希望它在每次测试中运行一次,请执行以下操作:

If you want it to run ONCE PER TEST, do the following:

Test Plan (Set thread groups to "run consecutively"
 - Cookie Manager
 - Thread Group A (1 thread, 1 loop)
 - - -  Login Logic
 - Thread Group B
 - - - Rest of test

请注意,如果您需要在线程组 A 和 B 之间共享任何变量,则需要将它们设置为属性.变量不能在线程组之间共享,但属性可以.为此,您需要使用属性函数.

Please note, if you need to share any variables between threadgroups A and B, you need to set them as properties. Variables cannot be shared between thread groups, but properties can. You'll need to use the properties function for this.

函数 __setProperty 自动将值存储为全局变量.启动 __setProperty 的最简洁方法是创建一个 POST 处理器 Beanshell 脚本作为在 THREAD A 中创建 cookie 的采样器的子项.要检索 THREAD B 中的值,您添加 __property 函数作为参数的 VALUE需要 cookie 值.

The function __setProperty automatically stores the value as a global variable. The cleanest way to initiate __setProperty would be to create a POST-processor Beanshell script as a child to the sampler that creates the cookie in THREAD A. To retrieve the value in THREAD B, you add the __property function as the VALUE for the parameter that needs the cookie value.

Beanshell 脚本如下所示:

The Beanshell script would look something like this:

props.put("COOKIENAME","COOKIEVALUE");   //creates a property "COOKIENAME" with value "COOKIEVALUE" 
print(props.get("COOKIENAME"));   //prints the value out to the console

上面的代码对于 COOKIENAME 总是具有相同的值,而不是想法.所以,我们需要确保COOKIEVALUE"是动态的.我建议使用 POST-PROCESSOR 正则表达式来提取 cookie 值,然后将其传递到 beanshell 脚本中.

The code above would always have the same value for COOKIENAME, less then idea. So, we need to make sure "COOKIEVALUE" is dynamic. I would recommend putting a POST-PROCESSOR regular expression to extract the cookie value, and then pass that into the beanshell script.

所以,我们的测试计划现在看起来像这样:

So, our test plan now looks like this:

Test Plan (Set thread groups to "run consecutively"
 - Thread Group A (1 thread, 1 loop)
 - - -  Login Logic
 - - - - -  Regex to grab cookie, store as "regexCookie"
 - - - - -  Beanshell to set property
 - Thread Group B
 - - - Rest of test

我们的 beanshell 脚本现在看起来像:

And our beanshell script now looks like:

props.put("COOKIENAME",vars.get("regexCookie"));   //creates a property "COOKIENAME" with value from "regexCookie"
print(props.get("COOKIENAME"));   //prints the value out to the console

用户手册链接:

这篇关于JMeter - 为什么一次只有控制器运行多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆