apache / jmeter

Apache JMeter open-source load testing tool for analyzing and measuring the performance of a variety of services
https://jmeter.apache.org/
Apache License 2.0
8.35k stars 2.09k forks source link

User Parameters do not work in HTTP Cookie Manager #1363

Closed asfimport closed 17 years ago

asfimport commented 20 years ago

Vibhav Garg (Bug 28715): In our app we need to assign cookie values using User Parameters. However, right now, variable expansion does not work in HTTP Cookie Manager.

Votes in Bugzilla: 1 Severity: normal OS: All

asfimport commented 20 years ago

Sebb (migrated from Bugzilla): Could you attach a simple test case that shows the problem, please?

asfimport commented 20 years ago

rino (migrated from Bugzilla): Created attachment cookie.jmx: simple test plan

asfimport commented 20 years ago

rino (migrated from Bugzilla): I'm having the same problem, although I'm using the "User Defined Variables" defined in the "Test Plan". In the file I attached, I set a "domain" variable, and I try to use it for the cookie domain. Won't work :(

asfimport commented 20 years ago

Charles Eakins (migrated from Bugzilla): We are also seeing this bug, with user variables and built in variables like ${_StringFromFile(file-path)}. We need to change a value in the cookie to about a hundred different combonations. BTW keep up the good work, I really like what I have seen so far, in fact better than loadrunner.

asfimport commented 20 years ago

Sebb (migrated from Bugzilla): [Thanks for the sample]

I've had a quick look at the code, and the Cookie Manager stores its values in a slightly different way from (most) other test elements - the result is that it treats them as fixed strings, and does not try to interpret them as functions/variables.

asfimport commented 19 years ago

theshaman (migrated from Bugzilla): I just want to say I also face with this limitation (not possible to add personalized cookies to each user threads, using user variables or other means) of JMeter. I think it could be a very useful enhancement of JMeter. Nevertheless congratulations and thanks for your work.

asfimport commented 19 years ago

Stephen Cooper (migrated from Bugzilla): This patch allows the expansion of UserParameters and Function calls in the Cookie Manager. It does so by no longer overriding the setRunningVersion and recoverRunningVersion methods. As a result of no longer overriding these, I had to create some way to accurately reset cookies for each iteration. So I introduced a variable "temporaryCookies" which gets populated with the cookie name of any cookie to remove - any cookie added while isRunningVersion is set to true.

Created attachment CookieManager.patch: Fix to allow expansion of functions and user parameters in the CookieManager

CookieManager.patch ````diff Index: src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java =================================================================== RCS file: /home/cvspublic/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java,v retrieving revision 1.40 diff -r1.40 CookieManager.java 33a34,35 > import java.util.HashSet; > import java.util.Iterator; 34a37 > import java.util.Set; 67a71,72 > > private Set temporaryCookies = new HashSet(); 177,184d181 < public void recoverRunningVersion() { < // do nothing, the cookie manager has to accept changes. < } < < public void setRunningVersion(boolean running) { < // do nothing, the cookie manager has to accept changes. < } < 196a194,196 > if (isRunningVersion() && getClearEachIteration()) { > addTemporaryCookie(c.getName()); > } 202a203,219 > public void recoverRunningVersion() { > if (log.isDebugEnabled()) { > log.debug("start recoverRunningVersion, now we have " + getCookieCount() + " cookies."); > } > if (temporaryCookies.size()>0) { > Iterator itr = temporaryCookies.iterator(); > while (itr.hasNext()) { > removeCookieNamed((String)itr.next()); > } > } > temporaryCookies.clear(); > super.recoverRunningVersion(); > if (log.isDebugEnabled()) { > log.debug("end recoverRunningVersion, now we have " + getCookieCount() + " cookies."); > } > } > 220c237 < log.debug("Clear all cookies"); --- > log.debug("Clearing " + getCookieCount() + " cookies"); 428c445,447 < --- > private void addTemporaryCookie(String cookieName) { > temporaryCookies.add(cookieName); > } ````
asfimport commented 19 years ago

Stephen Cooper (migrated from Bugzilla): Oh yeah - forgot to mention. The patch I just uploaded is against the following version: [coop@cstephen jakarta-jmeter]$ cvs status src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java

File: CookieManager.java Status: Locally Modified

Working revision: 1.40 Repository revision: 1.40
/home/cvspublic/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java,v Sticky Tag: v2_1_1 (revision: 1.40) Sticky Date: (none) Sticky Options: (none)

asfimport commented 17 years ago

Alf Hogemark (migrated from Bugzilla): I have been briefly looking at this.

The following short patch seems to make it possible to use functions and user parameters in the CookieManager.

Index: C:/Documents and Settings/alf/workspace/Jmeter/src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java

--- C:/Documents and Settings/alf/workspace/Jmeter/src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java (revision 519613) +++ C:/Documents and Settings/alf/workspace/Jmeter/src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java (working copy) @@ -290,7 +290,10 @@ int i=0; for (PropertyIterator iter = getCookies().iterator(); iter.hasNext();) { Cookie jmcookie = (Cookie) iter.next().getObjectValue();

However, I'm not sure this is the correct way of fixing this. I have not looked much at the CookieManager code. Are there threading issues involved ? I.e. can different threads be accessing the cookies at the same time ? In that case, the different threads can set and unset the running version. Or do each thread have it's own instance of the CookieManager and all other ConfigTestElement ? If each thread have their own CookieManager, I think the simple patch above is correct.

Do we want to only allow variable expansion in the static cookies, and not in the runtime cookies received during sampling ?

Perhaps Stephen Cooper's patch from 2005-10-10 looks better, but the code seems to have changed a bit since his suggestion.

Could we just call "setRunningVersion(false); setRunningVersion(false);" on each cookie as the first thing to do in "testIterationStart" ? Or will we get threading issues here as well ?

And also call "setRunningVersion(false);" on each cookie on "testEnded" ? Perhaps that is not needed, as it seems like the GUI recreates all the cookies "static cookies" when you go to the CookieManager GUI. I'm at least unable to figure out when all the dynamic cookies are deleted, but I never see them in the GUI.

Or should we add a flag to the Cookie class, so we know which ones are static and which ones are dynamic, and then loop over all the static ones in the following methods in CookieManager : public void recoverRunningVersion() public void setRunningVersion

I'm sorry for all the questions, but this bug seems like an "easy" one to fix, and quite important.

Any comments ?

asfimport commented 17 years ago

Sebb (migrated from Bugzilla): Code has been added to Cookie Manager in SVN r571789.

Just in case it causes a problem, one can set the property:

CookieManager.allow_variable_cookies=false

to disable the fix.

asfimport commented 13 years ago

jimmyxu (migrated from Bugzilla): hi I am not sure whether I have got correct configuration of Jmeter, but I do see user parameter is not work in cookie manager. I got this problem both Jmeter 2.4 and Jmeter 2.5.1 reproduce step:

  1. Create http request to access a website
  2. Create a regular expression extractor to get a SessionID value as SessID variable
  3. Create a HTTP Cookie Manager to reference SessID(${SessID})

result: $SessID is treated as a string not a variable (but this variable works in http sampler.)

expected: $SessID is treated as a variable

asfimport commented 13 years ago

Sebb (migrated from Bugzilla): (In reply to comment 11)

hi I am not sure whether I have got correct configuration of Jmeter, but I do see user parameter is not work in cookie manager. I got this problem both Jmeter 2.4 and Jmeter 2.5.1 reproduce step:

  1. Create http request to access a website
  2. Create a regular expression extractor to get a SessionID value as SessID variable
  3. Create a HTTP Cookie Manager to reference SessID(${SessID})

result: $SessID is treated as a string not a variable (but this variable works in http sampler.)

expected: $SessID is treated as a variable

WOrks fine for me; note that the Cookie Manager is a configuration element so only resolves variables at the start of a loop.

asfimport commented 13 years ago

jimmyxu (migrated from Bugzilla): (In reply to comment 12)

(In reply to comment 11) > hi > I am not sure whether I have got correct configuration of Jmeter, but I do see > user parameter is not work in cookie manager. I got this problem both Jmeter > 2.4 and Jmeter 2.5.1 > reproduce step: > 1. Create http request to access a website > 2. Create a regular expression extractor to get a SessionID value as SessID > variable > 3. Create a HTTP Cookie Manager to reference SessID(${SessID}) > > result: $SessID is treated as a string not a variable > (but this variable works in http sampler.) > > expected: $SessID is treated as a variable

WOrks fine for me; note that the Cookie Manager is a configuration element so only resolves variables at the start of a loop.

Thanks. I misunderstand user parameter, user parameter works well. What I want to do is reset cookie value for a http smapler, is there any method can do that in Jmeter?

Jimmy

asfimport commented 13 years ago

Sebb (migrated from Bugzilla): Bugzilla is not a support forum.

Please subscribe to the JMeter user list and ask there.