Forum Discussion

Etks's avatar
Etks
Occasional Contributor
7 years ago
Solved

Problem with random number generation (ThreadLocalRandom) in LoadUI Pro

I have testcase in SoapUI that I've used to create a testcase in LoadUI Pro.

 

The testcase has two steps: The first is a Groovy script in which I create two sets of geographic coordinates (latitude/longitude pairs). In the second step I send these coordinates in a REST request.

 

It is important that these coordinates are 1) random, and 2) not too far apart. I've done this by randomly generating one set of coordinates, and then adding a small number (also random) to the latitude and longitude to get the second coordinate pair.

 

When I run this testcase on its own, everything is dandy. We've actually been using it for weeks now and run it once a day, and the coordinates are always within the bounds. But when I used the testcase in LoadUI, things went badly.

 

I've noticed two things that shouldn't happen:

 

1) Many of the generated coordinates (but not all of them) are too far apart, hundreds of kilometers more than they should be.

2) I wrote the script so that the second set of coordinates is always to the southeast of the first. But in the load test this is often not the case.

 

I can't find a mistake with the script itself, so my hunch is that the problem lies with LoadUI's parallel execution. I'm using ThreadLocalRandom to generate the numbers. In the load test I use 1000 virtual users to generate load. 

 

Here is my script:

 

 

//Set minimum and maximum values for the latitude and longtitude so that the results lie within borders
double minLat = 47.9
double maxLat = 54.1

double minLng = 8.5
double maxLng = 12.1

//Calculate random numbers based on the minimum and maximum values defined above

double lat1 = java.util.concurrent.ThreadLocalRandom.current().nextDouble(minLat, maxLat) double lng1 = java.util.concurrent.ThreadLocalRandom.current().nextDouble(minLng, maxLng) //To calculate the other latitude/longitude pair, a value between 0.01 and 0.06 is added
double diffCoordinates = java.util.concurrent.ThreadLocalRandom.current().nextDouble(0.01, 0.06) double lat2 = lat1 - diffCoordinates //lat2 is further south double lng2 = lng1 + diffCoordinates //lng2 is further east testRunner.testCase.testSuite.project.setPropertyValue("testdata.randomLatitude", lat1.toString()) testRunner.testCase.testSuite.project.setPropertyValue("testdata.randomLongitude", lng1.toString()) testRunner.testCase.testSuite.project.setPropertyValue("testdata.randomLatitude2", lat2.toString()) testRunner.testCase.testSuite.project.setPropertyValue("testdata.randomLongitude2", lng2.toString())

 

Addendum: Just as I was about to post it occurred to me that the random number generation could be a red herring. Maybe it's the addition of one variable to another (such as in the line "double lat2 = lat1 - diffCoordinates")

 

I'd be grateful for any help or advice to solve this problem.

 

  • Nevermind, I found the solution. Saving the variables on the property level was the problem. Changing the last four lines to this solved the problem.

     

    testRunner.testCase.setPropertyValue("testdata.randomLatitude", lat1.toString())
    testRunner.testCase.setPropertyValue("testdata.randomLongitude", lng1.toString())
    
    testRunner.testCase.setPropertyValue("testdata.randomLatitude2", lat2.toString())
    testRunner.testCase.setPropertyValue("testdata.randomLongitude2

     

1 Reply

  • Etks's avatar
    Etks
    Occasional Contributor

    Nevermind, I found the solution. Saving the variables on the property level was the problem. Changing the last four lines to this solved the problem.

     

    testRunner.testCase.setPropertyValue("testdata.randomLatitude", lat1.toString())
    testRunner.testCase.setPropertyValue("testdata.randomLongitude", lng1.toString())
    
    testRunner.testCase.setPropertyValue("testdata.randomLatitude2", lat2.toString())
    testRunner.testCase.setPropertyValue("testdata.randomLongitude2