Forum Discussion

SaraCavelind's avatar
SaraCavelind
Contributor
13 years ago

Load testing with mocked servcies

Hi!
We have developed a mock server (17 services) that we use to easy the testdata handling. Now we're considering load testing applications that use the mock server.
I realise that the mockserver might now become a problem in itself since I have not done anything to make the mock dispatch scripts threadsafe.
I'm a technical tester and find that this might be a little to difficult but I'm willing to give it a try before I call someone....

Is there any hints on what I need to do in order to make my dispatch scripts better so it can handle load?
This is the dispatch script. In summary it checks if a has of the request exists on disk, then loads it; otherwise calls the real backend, saves the file and returns the response.
import com.eviware.soapui.model.testsuite.TestRunner.Status
import com.eviware.soapui.impl.wsdl.WsdlProject
import com.eviware.soapui.impl.wsdl.WsdlInterface
import com.eviware.soapui.impl.wsdl.WsdlRequest
import com.eviware.soapui.impl.wsdl.WsdlSubmitContext
import com.eviware.soapui.impl.wsdl.WsdlSubmit
import com.eviware.soapui.model.iface.Response
import com.eviware.soapui.model.mock.MockResponse

def holder = new com.eviware.soapui.support.XmlHolder( mockRequest.requestContent )

def idSSN=holder["//*:ssn"]

outputDir=context.expand( '${#Project#outputfolder}')
def BindingName="getPerson-2.0Binding"
def operationName="getPerson-2.0Op"
def requestName="Request 1"
def outputLocation="${outputDir}${BindingName}/"
log.info "Data sparas till:${outputLocation}"

// get reference to project
WsdlProject project = (WsdlProject)mockOperation.mockService.project
// get reference to request
WsdlRequest request = (WsdlRequest)project.interfaces["${BindingName}"].operations["${operationName}"].getRequestByName("${requestName}")

// set request content from incoming mockRequest
request.setRequestContent(mockRequest.getRequestContent())

// get util testcase
def testCase = project.testSuites["utils"].testCases["hashContent"]
// set arguments as properties
testCase.setPropertyValue( "content", mockRequest.requestContent )

// run testCase
def runner = testCase.run( new com.eviware.soapui.support.types.StringToObjectMap(), false )

fileHashName="-"+testCase.getPropertyValue( "hash" )


if(idSSN)
{
fullFileName="${outputLocation}"+idSSN+fileHashName
log.info "SSN"
log.info idSSN
}

// Change for each service
log.info (fullFileName)

def fileH = new File( fullFileName)
if (fileH.exists()==false)
{
log.info "Filen finns inte, hämtar och sparar!"


WsdlSubmit submit=request.submit( new WsdlSubmitContext( request ), false )
// wait for the response

Response response = submit.getResponse();
// get reference to MockResponse

requestContext.responseMessage = response.getContentAsString()

def fileW = new File(fullFileName)
fileW.createNewFile()
fileW.setWritable(true, false)
log.info "Skrivbar:"+fileW.canWrite()
log.info "Innehåll"
log.info requestContext.responseMessage
fileW.write(requestContext.responseMessage)
}
else
{
log.info "Filen existerar redan"
requestContext.responseMessage=fileH.getText()
}

5 Replies

  • Hi Sara!

    SoapUI MockServices are not optimized to handle high load, but they should be thread safe.

    After a quick glance, yYour code looks correct -- I can't see why it should fail in a concurrent environment. Performance-wiser, I have a feeling that one of the bottlenecks in your code might be disk I/O (i.e. many threads writing/reading to the disk at once).

    Hälsningar

    Henrik O
    SmartBear Software
  • Hi Henrik!
    Actually my real name is Fredrik Cronholm (working at Folksam, perhaps I'll see you on thursday?), but the sales department uses a license broker and we got this logon...
    I see codesnippets lookign like this in various places:
    def String callLogin()
    {
    //Use the shared object created in the Setup Script for synchronization
    synchronized(context.LoadTestContext.lock)
    {
    log.info 'Login inside'
    ...
    }

    but this method (syncronized) is nothing you think I'll need?

    Disk I/O could be a problem in terms of throughput, but the main point is to get a stable env where I can compare the results from release to release.
  • Hmmm, when taking a closer look:

    The request and testCase objects are shared resources which you are modifying. You need to synchronize all of the code touching those objects. This will probably damage performance, but you can try to see what happens. Try to make this synchronized block as small as possible (move down the instantiation of request?).

    Regards

    Henrik O
    SmartBear
  • SaraCavelind wrote:
    Hi Henrik!
    Actually my real name is Fredrik Cronholm (working at Folksam, perhaps I'll see you on thursday?), but the sales department uses a license broker and we got this logon...

    Oh, I see

    Yes, I'll be at MeetUI today!

    /Henrik O
  • Hi!
    Is it possible for you to provide some more input on this like a suitable set of syncronize's..? I've tried to run multiple threads against the mocksetup, and of course it failed at once (getting wrong data back..) .... I've tried to use synchronized, but I lack the suitable competences..