Forum Discussion

ASai5's avatar
ASai5
New Contributor
14 years ago

LoadUI threads causes a record to be used again

Hi Everybody,

I started using LoadUI recently and I am facing an issue. I have a testsuite with a simple Groovy script that increment a parameter and a request that uses that value.
I started my LoadUI with a rate of 1/sec and Request limits of 5. It worked fine. Then I started increasing the rate to 5/sec and Request Limits to 100. I started seeing some of the records that were already used being used again causing the requests to fails as the records were already in the database.

I would like some help on fixing this issue by having the threads not re-using already used records.

My LoadUI setup is just a Fixed Rate Generator, a SOAPUI runner and Statistics component.

Simple Groovy script to increment my parameter and insert in the Properties:
***
String scounter = '';
Integer icounter = 0;
String dataString = '';
def props = new java.util.Properties();

props = testRunner.testCase.getTestStepByName("Properties");

scounter = props.getPropertyValue('COUNTER');
icounter = scounter.toInteger();
icounter++
scounter = icounter.toString();
props.setPropertyValue('COUNTER', scounter);

length = 32 - scounter.length();
dataString = "55555555555555555500000000000000"
dataString = dataString.substring(0,length)
props.setPropertyValue('CIN', dataString + scounter);
***

I have attached a screen shot. The records were incrementing correctly up to xxxxxx163 but then xxxxxx002.

This should work but I am also thinking about using DataSource or a Groovy script that read from csv file.

I would greatly appreciate your help and/or inputs.

Thanks!
  • Hi!

    abuadam97 wrote:
    scounter = props.getPropertyValue('COUNTER');
    icounter = scounter.toInteger();
    icounter++

    Here you are getting and increasing a property value.

    There are two problems with this:

    • loadUI will create a copy each of the TestCase to all threads that are running this simultaneously. This means that the COUNTER property always will be what it was set to originally.

    • Even if the threads would share this property, you'd have to do the operation on COUNTER as one atomic transaction to avoid concurrency issues.


    Concurrency is complicated and very complex to script yourself.

    I would use a DataSource TestStep set to shared instead. That will take care of all concurrency issues automatically, and that is how we have intended users to approach these kind of problems.

    Hope this helps!

    Henrik
    SmartBear Software
  • ASai5's avatar
    ASai5
    New Contributor
    Thanks Henrik.
    DataSources working perfectly in our project.