3
votes

(there seem so be various problems regarding the CookieManager, but I could not find my problem while searching)

I'm trying to figure out why the Cookie Manager isn't keeping my cookie, but I'm running out of ideas.

Using jmeter 2.13

I have the following Test Plan setup:

- 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!)

Each request returns 200, there are no redirects anywhere (except where the second thread redirects to the login page because it is missing the cookie)

My problem: prior to entering Thread Group 2, the log says that the CookieManager has cleared all cookies. I can't see why - isn't it supposed to keep them, since the header Manager is a top-level element?

here is the section of the log that shows this (the line in question is marked with ######):

    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 

I've tried changing some settings in jmeter.properties:

 CookieManager.save.cookies=true

as well as

CookieManager.check.cookies=false

but neither seems to work.

My first theory was that it has to do with the fact that the cookie in question has no expiry added, but I do not see an error when adding it - just that it gets deleted again when it should not.

2

2 Answers

2
votes

You are misunderstanding Thread groups and Cookiemanager.

First each thread has its own version of Cookie which is updated after each sample done by the thread

Second, variables nor any object associated to a thread like cookiemanager are shared by threads so not at all by 2 thread groups.

Even if Dmitri points at Beanshell it is not a good idea for performance or maitainability of scripts to share thing among threads in different thread groups.

I think you are using 2 different thread groups but instead should be using only 1 this will fix your issue.

0
votes

Option 1:

Use JMeter's __setProperty() function to convert variables to properties. JMeter Variables scope is limited to current thread group only, and JMeter Properties are in fact java.util.Properties so they are global for the whole JVM.

Option 2:

Use scripting to extract cookies names and values (along with domain, expires, secure, etc. fields). This approach is more complicated but it gives more control and flexibility. See How to use BeanShell: JMeter's favorite built-in component guide for example code of sharing cookies between different thread groups.