Search code examples
testingjmeterbeanshell

Resetting a COOKIE_ var each thread iteration


Is there a way to reset/clear a COOKIE_ variable each iteration iteration of a thread in a thread group?

"Clear cookies each iteration" option is set in the HTTP Cookie Manager. The problem is that COOKIE_vars do not get reset when the thread restarts (but the real cookies do, as they should). (This is seen when logging it with sample_variables option.)

Have tried:

  • using User Defined Variables, but that only seems to run on the first iteration
  • using BeanShell Sampler with vars.put("COOKIE_var", "null"); works, except that you get a useless extra sample in the log, which is not acceptable
  • using a BeanShell pre/post processor with the same code doesn't work because the exact first sample is not always known (user configurable)

So if there was a way to execute some code without a sample log entry being generated, that would solve it. But haven't found anything to just run some code, nor any way to "cancel" the sample in BeanShell Sampler so that there would be no log of it.


Solution

  • Using an empty If Controller with the following condition works (it does reset the variable and it is executed every iteration without generating a sample):

    ${__BeanShell(vars.remove("COOKIE_var"); "false";)}
    

    Altho using a controller like this just to run some code seems a bit ugly.

    "false" is in there to return a value that doesn't generate a JS or condition exception.