Forum Discussion

wrxdude144's avatar
13 years ago

Is context.expand thread safe?

I had a need to extract a value from a soap response, and use that value in a later call. After some googling this method seemed to be the recommended way:
stuff = context.expand('${GetList#Response#//ns1:out/*/*}')
// read in the xml fragment and give it the proper namespace
def records = new XmlSlurper().parseText(stuff).declareNamespace(msg:"http://mynamespace")

That worked great when I executed each test step individually. But when I tried it in a load test, it always failed with a 'premature end of file' exception. Under a load test, I believe the context.expand is trying to consume the same response over and over. Since it has already been read to the end once already, each subsequent call fails, thus generating the end of file exception.

I have fixed this with some more verbose code:
def myResponse = testRunner.testCase.getTestStepByName( "GetList").testStep.testRequest.response.getResponseContent()
// read in the xml fragment and give it the proper namespace
def records = new XmlSlurper().parseText(myResponse).declareNamespace(
msg:"http://mynamespace",
'SOAP-ENV':'http://schemas.xmlsoap.org/soap/envelope/',
ns1:'http://mynamespace.again',
xsd:'http://www.w3.org/2001/XMLSchema',
xsi:'http://www.w3.org/2001/XMLSchema-instance')

The above method seems to be thread safe. Question: why did the first call fail when run under a load test? Is context.expand trying to read the same response over and over?
No RepliesBe the first to reply