dfche
dfche

Reputation: 3693

How to get a separate context in different SoapUI testcase instances running in parallel?

I have a SoapUI test case (name "create entity") with groovy script test step which uses some variables received in context, e.g. counter value, processes it and returns some other value, e.g. returnId

// these variables are effectively shared across different threads, I want to avoid it
def threadId = context.getProperty("threadId")    
def counter = context.getProperty("counter").toInteger() 
...
testRunner.testCase.setPropertyValue("returnId", returnId)

And this test case is called from another test case groovy script step, which creates several threads with numerous test case executions

...
def counter = new AtomicInteger()
...

// multiple threads
1.upto(2) { 
  threads << new Thread({ 
    def tc = testRunner.testCase.testSuite.getTestCaseByName("create entity")
    def txInstanceContext = new com.eviware.soapui.support.types.StringToObjectMap() 
    // thread specific parameter
    def threadId = ...
    txInstanceContext.put("threadId", threadId)

    // multiple executions loop
    1.upto(2) {
      def number = counter.getAndIncrement().toString()     
      // execution specific variable
      txInstanceContext.put("counter", number)
      log.info "Started uploading " + number + " at " + new Date().getTime() 
      def runner = tc.run( txInstanceContext, false )      
      while(runner.status == Status.RUNNING) {
        this.sleep(50)
      }      
      log.info "Status: " + runner.status + ", time taken for upload was: " + runner.timeTaken + " ms"     
      ...
      assert runner.status != Status.FAILED : runner.reason  
      def returnId = tc.getPropertyValue("returnId")
      log.info "Finished uploading " + number + " at " + new Date().getTime() 
      log.info "Returned id: " + returnId 
      ...
    }
  })
}

threads.each { 
  it.start()
}
threads.each { 
  it.join()
}

How to get an isolated scope for each execution, to avoid overriding/setting test case variables by other thread executions?

Upvotes: 0

Views: 1369

Answers (1)

user1207289
user1207289

Reputation: 3253

I think you need to create a TC runner and then WsdlTestRunContext.

I ran into similar situation where I needed to create a TC runner. Here . I believe you can go one step further and create a context by using createContext(StringToObjectMap properties) method of this WsdlTestCaseRunner.

Upvotes: 1

Related Questions