cookies - jmeter 不会跨线程组保留 cookie

标签 cookies jmeter

(关于CookieManager的问题似乎有很多,但我在搜索时找不到我的问题)

我想弄清楚为什么 Cookie 管理器没有保留我的 cookie,但我已经没有办法了。

使用 jmeter 2.13

我有以下测试计划设置:

- HTTP Headers
- HTTP Cookie Manager ("clear each iteration" is NOT checked, policy=compatibility, tried both implementation options)
- Thread group 1
    -- perform login (returns a Set-Cookie header as expected)
- Thread groups 2-n
    -- send http queries using cookies from login (this is the plan!)

每个请求返回200,任何地方都没有重定向(除了第二个线程因为缺少cookie而重定向到登录页面)

我的问题: 在进入线程组 2 之前,日志显示 CookieManager 已清除所有 cookie。我不明白为什么 - 它不应该保留它们吗,因为 header 管理器是顶级元素?

这是显示此内容的日志部分(有问题的行标有######):

    2015/06/30 16:19:55 INFO  - jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 1 : TEST LOOP 0 - login 
    2015/06/30 16:19:55 INFO  - jmeter.engine.StandardJMeterEngine: Starting 1 threads for group TEST LOOP 0 - login. 
    2015/06/30 16:19:55 INFO  - jmeter.engine.StandardJMeterEngine: Thread will continue on error 
    2015/06/30 16:19:55 INFO  - jmeter.threads.ThreadGroup: Starting thread group number 1 threads 1 ramp-up 1 perThread 1000.0 delayedStart=false 
    2015/06/30 16:19:55 DEBUG - jmeter.protocol.http.control.CookieManager: Clear all cookies from store 
    2015/06/30 16:19:55 INFO  - jmeter.threads.ThreadGroup: Started thread group number 1 
    2015/06/30 16:19:55 INFO  - jmeter.engine.StandardJMeterEngine: Waiting for thread group: TEST LOOP 0 - login to finish before starting next group 
    2015/06/30 16:19:55 INFO  - jmeter.threads.JMeterThread: Thread started: TEST LOOP 0 - login 1-1 
    2015/06/30 16:19:55 DEBUG - jmeter.protocol.http.control.HC3CookieHandler: Found 0 cookies for [url edited] 
    2015/06/30 16:19:56 DEBUG - jmeter.protocol.http.control.HC3CookieHandler: Received Cookie: JSESSIONID_PUBLIC=swfw6xfdo0es18e5ux1xhad6a;Path=/url/edited;HttpOnly From: [url edited] 
    2015/06/30 16:19:56 DEBUG - jmeter.protocol.http.control.CookieManager: Add cookie to store server-edited   TRUE    /url/edited FALSE   0   JSESSIONID_PUBLIC   swfw6xfdo0es18e5ux1xhad6a 
    2015/06/30 16:19:56 INFO  - jmeter.threads.JMeterThread: Thread is done: TEST LOOP 0 - login 1-1 
    2015/06/30 16:19:56 INFO  - jmeter.threads.JMeterThread: Thread finished: TEST LOOP 0 - login 1-1 
    2015/06/30 16:19:56 DEBUG - jmeter.protocol.http.sampler.HTTPHC4Impl: Thread Finished 
    2015/06/30 16:19:56 INFO  - jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 2 : TEST LOOP 1 - search, high frequency, Ssd-Requests 
    2015/06/30 16:19:56 INFO  - jmeter.engine.StandardJMeterEngine: Starting 1 threads for group TEST LOOP 1 - search, high frequency, Ssd-Requests. 
    2015/06/30 16:19:56 INFO  - jmeter.engine.StandardJMeterEngine: Thread will continue on error 
    2015/06/30 16:19:56 INFO  - jmeter.threads.ThreadGroup: Starting thread group number 2 threads 1 ramp-up 20 perThread 20000.0 delayedStart=false 
    ##### 2015/06/30 16:19:56 DEBUG - jmeter.protocol.http.control.CookieManager: Clear all cookies from store ######
    2015/06/30 16:19:56 INFO  - jmeter.threads.ThreadGroup: Started thread group number 2 
    2015/06/30 16:19:56 INFO  - jmeter.engine.StandardJMeterEngine: All thread groups have been started 
    2015/06/30 16:19:56 INFO  - jmeter.threads.JMeterThread: Thread started: TEST LOOP 1 - search, high frequency, Ssd-Requests 2-1 

我试过更改 jmeter.properties 中的一些设置:

 CookieManager.save.cookies=true

还有

CookieManager.check.cookies=false

但似乎都不起作用。

我的第一个理论是,它与所讨论的 cookie 没有添加过期这一事实有关,但我在添加它时没有看到错误 - 只是它在不应该被删除的时候又被删除了。

最佳答案

您误解了线程组和 Cookiemanager。

首先,每个线程都有自己的 Cookie 版本,该版本在线程完成每个样本后更新

其次,变量或与线程关联的任何对象(如 cookiemanager)都由线程共享,因此根本不会被 2 个线程组共享。

即使 Dmitri 指出 Beanshell,在不同线程组中的线程之间共享东西对于脚本的性能或可维护性来说也不是一个好主意。

我认为您正在使用 2 个不同的线程组,但应该只使用 1 个,这将解决您的问题。

关于cookies - jmeter 不会跨线程组保留 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31141205/

相关文章:

javascript - 是否可以在用户离开时删除整个网页?

javascript - 将用户保存在 cookie 中( header 已发送)

xpath - 使用 JMeter 中的 XPath 查询从 HTML 中的选择元素中提取值

regex - Jmeter提取字段/解析JSON响应

java - JMeter - 无法在 JSR223 脚本中使用 Java 流

JMeter 循环使用不同的测试方法

java - 来自响应的 Internet Explorer Cookie 不会覆盖现有 Cookie

cookies - 使用 Supertest 时 request.cookies 未定义

java - 通过 HttpClient 接受所有 Cookie

regex - 如何在 Jmeter 中获取响应数据(sid)?