cancel
Showing results for 
Search instead for 
Did you mean: 

Mockservice concurrent requests failing

New Contributor

Mockservice concurrent requests failing

Hi,

 

When sending concurrent test requests to a SOAP mock service I am having issues with tests randomly failing or passing and was hoping for some help. 

 

In my MockResponse for this transaction within the MockOperation of the mock service, I have a variable context.content which contains the body of the response. The content of this context.content is XML pulled from my local file system, determined by a function, getResponse() which takes into account a couple of key fields in the request to determine which file contents to put into context.content (and therefore what the MockResponse looks like).

 

It looks like when sending in concurrent transactions, because all transactions are using there own instance of getResponse() to edit context.content, the mock service gets confused and sends back incorrect responses with duplicate contents. I can see in the script log in SOAPUI that for each transaction that processing for getResponse() is happening and complete, but I suspect context.content is not getting updated before the mock service returns its MockResponse.

 

I have tried synchronising getResponse() as per this thread: https://community.smartbear.com/t5/SoapUI-Open-Source/Multi-threading-in-SoapUI-Mock-Service/td-p/10... but haven't had any success.

 

 

context.lock = new Object()

def getResponse() {
    synchronized(context.lock) {
          // do stuff
          .....
          return response
     }
}

 

 

It is probably also worth menitoning that getResponse() sits in a seperate Groovy script which is called from the MockResponse script. However I have also tried synchronising the call to this script (as well as inlcuding all the logic of getResponse()) in the MockResponse script and this still does not work.

 

 

context.lock = new Object()

synchronized(context.lock) {
    ….
    instance = externalScript.newInstance()
    instance.getResponse()
}

I have also recreated a simple MockService which has much simplier processing in choosing the response to be returned and have noticed that this confusion in what is returned is still there.

 

Is there a way of using a context based variable in a multi-threaded way, allowing for a mock service to accept multiple concurrent requests with processing to update that variable? 

 

Thanks

 

 

2 REPLIES 2
Community Hero

Re: Mockservice concurrent requests failing

I am not sure if get the basic thing. Mockservice enables you to design the tests before actual application is ready.

Not sure if it is really needed to implement concurrency tests on mock.



Regards,
Rao.
Highlighted
Community Hero

Re: Mockservice concurrent requests failing

Hi,

 

You shouldn't need to do any synchronization stuff.

 

Is this a Dispatch script or an OnRequest script? In Dispatch script, I suggest you try putting the variable into requestContext instead of context.

 

Otherwise, I'd need to know a bit more about what your scripts do and how.

 

New Here?
Join us and watch the welcome video:
Top Kudoed Authors