Forum Discussion

pkitkows's avatar
pkitkows
Occasional Contributor
10 years ago

LoadTest - How to read/edit file/property in thread-safe way

Hi,
I'm trying to do some exercise with using SOAP UI and LoadTest function. My goal is to have test case/step which read data from property (as LIST) on the case/suite/project level (no matter), get first value and remove it from the list.

It's working fine during single execution (SOAPUI).

When I launch test case from LoadTest and use few threads, it happened sometimes that two or more threads read the same value.

Is there any way to assure that reading and remove value from list (or file) will be done in thread-safe mode ?

Any hints how to resolve that kind of issue ?

Regards,
Piotr

6 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    There are two possible options as solution to the problem and see if the problem goes.
    1. Have a Test Delay in load test
    2. otherwise a have delay step before reading value.
  • pkitkows's avatar
    pkitkows
    Occasional Contributor
    Rao,

    Thank you for quick response.

    How delay will resolve this kind of issue ?

    Doesn't occurrence of this issue still be time("luck") randomized ?

    I have tried this:

    - Test Suite ( Property LIST - contains some entities)
    -- Test Case
    --- Test Step - groovy script which:
    ---- get LIST from SUITE
    ---- take first entity
    ---- remove first entity from LIST
    ---- save new LIST on the SUITE level
    --- Test step - some REST request based on data from groovy
    --- Test step - delay (randomized in range 0-50 ms) -> Added as you suggested
    --- Test step - groovy - do loop - jump to the first test step as long as LIST is not empty

    Unfortunately, this didn't help at all


    I tough that variables on case level are independent when you are using LoadTest, while a variables on the test suite/project level are shared between threads during LoadTEst execution.

    Does "PRO" version has some WA/solution ?

    Regards,
    Piotr
  • nmrao's avatar
    nmrao
    Champion Level 3
    I dont think pro has any different way for this. See if you can have groovy script that can do the update of the properties in synchronized method
  • pkitkows's avatar
    pkitkows
    Occasional Contributor
    Rao,

    I think you have right that a groovy script will be the best solution, however I'm still looking for any example on the web how to do that

    Regards,
    Piotr
  • pkitkows's avatar
    pkitkows
    Occasional Contributor
    I could use bellow code to serialize a list and get/remove first item from the list.

    myList = ["0", "1", "2", "3"]
    List<String> mySynchronizedList = Collections.synchronizedList(myList);

    order = mySynchronizedList.remove(0)
    log.info ("order: " + order)

    However, the mySynchronizedList has limited scope to only test step (groovy script).

    How I could do this globally ? (per suite, project)
    How can I return object from test step which will be accessible from another step?

    Regards
  • nmrao's avatar
    nmrao
    Champion Level 3
    Looks like you need to use the same list in all the threads. So, in the test read a copy of it and then work on that list and continue your steps.
    So that the same list is availble for other runs, otherwise you would get nothing as the list is going to be emptied.