Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jMeter thread sequence

I have a JMeter test plan with following http request samplers.

  1. Login
  2. Call some functionality which needs a logged in user
  3. Logout

When I execute the test plan with 5 parallel threads, I see that the sampler 2 is called before calling sampler 1 for some threads, which then fails the response assertions.

Is there any way to specify a sequence of samplers to be executed ?

like image 982
rangalo Avatar asked Jun 22 '12 12:06

rangalo


People also ask

What is the order of execution in JMeter?

To remember the execution order, use the acronym CONF-PTS-PAL. When you click on Run button for the above test plan, first JMeter will look for any configuration elements are present or not. If it finds, those will be executed first. Then it looks for any Pre Processors and then Timers.


1 Answers

This should ensure that they are executed sequentially :

enter image description here

So let's start with thread group.

Number of Threads(users) is 5.

So assuming you have the logic work out for your login sampler. Just add additional sampler to it. So right click on that sample Add > Post Processors > BSF PostProcessor, inside this post processor big script space write ${__setProperty(ThreadValue,${__threadNum},)}.

This will save the thread number to your property called ThreadValue. Make sure you select your language as beanshell in the dropdown list.

Then after the login sampler add the if controller. Add this to the condition field (${JMeterThread.last_sample_ok}==true) && (${__property(ThreadValue,,)} == ${__threadNum})

What this means is that -> do only logged in stuff while the actual login is successful and if the login thread matches the thread you're currently in.

That's it you do your login stuff only inside the if controller. If you want to be sure that you logout the right user place additional if controller arround it.

Cheers

like image 166
ant Avatar answered Oct 21 '22 09:10

ant