Forum Discussion

max80's avatar
max80
Occasional Contributor
13 years ago

updating properties in LoadTestContext

Hi everyone,

I am trying to synchronize a counter in soap ui when running loadtest. I have studied following links:

http://www.soapui.org/forum/viewtopic.php?f=2&t=6365
http://www.soapui.org/forum/viewtopic.php?t=7218
http://www.soapui.org/Load-Testing/loadtest-scripting.html
http://www.soapui.org/Scripting-Properties/tips-a-tricks.html

However I can't find a way to reference shared variable (from loadTestContext) in the body of the request (same value goes to each virtual user). I am sure something is wrong with my understanding of the contexts, but can't see it. I checked property expansion help and can't see a way to reference load test context.

Please help!

My latest attempt:

if( context.LoadTestContext ) {
synchronized( context.LoadTestContext ) {

if( !context.LoadTestContext['init'] ) {
context.LoadTestContext['init'] = true
context.LoadTestContext['counter'] = context.testCase.getPropertyValue("prop_counter")

}

def mycounter = context.LoadTestContext['counter'].toInteger()
mycounter++
mycounter.toString()
context.LoadTestContext['counter'] = mycounter
context.testCase.setPropertyValue("prop_counter", mycounter)
}
}
  • max80's avatar
    max80
    Occasional Contributor
    Perhaps someone could just share sample working project, I will figure out the details by myself.

    As an alternative I started playing with ${ThreadIndex} parameter, but it seems to me it will introduce too much overhead... And I would really love to make this LoadTestContext work, I see that value itself is updated if I mess something up with properties in the script - load test throws errors with ordered not duplicated values.
  • max80's avatar
    max80
    Occasional Contributor
    It looks like I made some progress, but still not there yet...

    Initialization script (groovy test step):

    if( context.LoadTestContext ) {
    synchronized( context.LoadTestContext ) {

    if( !context.LoadTestContext['init'] ) {
    context.LoadTestContext['init'] = true
    context.LoadTestContext['counter'] = '5'
    }
    }
    }


    Updating variable script (groovy test step):

    def mycounter = context.LoadTestContext['counter'].toInteger()
    mycounter++
    context.LoadTestContext['counter'] = mycounter



    Property is defined as follows:

    ${=(context.LoadTestContext['counter'])}


    Problem with this solution is that even for 5 threads I observe a race condition, sometimes values in the requests are duplicated. I guess it has something to do with updating variable outside of LoadTestContext, but if I move update code inside initialization script property returns null value.
  • max80's avatar
    max80
    Occasional Contributor
    It looks even when I wrap update script in synchronized I observe the same race condition:

    synchronized (context.LoadTestContext) {
    def mycounter = context.LoadTestContext['counter'].toInteger()
    mycounter++
    context.LoadTestContext['counter'] = mycounter
    }


    Am I doing something wrong or is there a bug in the tool?
  • max80's avatar
    max80
    Occasional Contributor
    I start only five threads on dual-core processor and it very often spits duplicated values for these scripts.

    This lack of answers is disappointing...
  • The valuation of the property also depends upon the calculations made on the capital gain tax, determining the values of the estate proceedings. Thanks…