Search code examples
testinggroovyjmeterload-testing

Is there a way to set up number of users for different thread in JMeter 5.3?


I am currently working on testing small API in our company and I need to randomly distribute a number of calls on all methods of that API. I am using 5.3 version of JMeter, company security politics, so we do not have newer versions if that matters.

Because number of methods is around 15 my idea right now is supply .properties file to JMeter, which will contain overall number of calls to API, then, through JSR223 sampler in SetUp Thread Group I will set properties with random amount of users in thread. However, I encountered a problem in doing so: I successfully set all properties, but I cannot access them, when calling ___property function in another Thread groups.

Is there any method to set those properties by script and access them through JMeter function?

Edit: Adding the code I am using in SetUp Thread Group to add properties

jmeter_properties.load(new FileInputStream(new File('env.properties')));
def allUsers = jmeter_properties.get('number.of.users') as Integer;
def random = new Random();
def thisUsers = random.nextInt(allUsers);
allUsers = allUsers - thisUsers;

props.put('getProjectById.users', thisUsers);```

Solution

  • I'm not sure whether it's expected behaviour or a bug in JMeter which should be reported via JMeter Bugzilla, but I do confirm that:

    1. Your code is correct
    2. The generated value cannot be referenced either by __P() or by __property() functions calls

    However if you use __groovy() function the property is resolved just fine, so if you do something like:

    ${__groovy(props.get('getProjectById.users'),)}
    

    in the 2nd (or whatever thread group) you will get the outcome you're looking for

    enter image description here