[英]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, eg counter value, processes it and returns some other value, eg returnId 我有一个带有groovy脚本测试步骤的SoapUI测试用例(名称为"create entity"
),该脚本使用在上下文中接收的一些变量,例如计数器值,对其进行处理并返回一些其他值,例如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 这个测试用例是从另一个测试用例groovy脚本步骤调用的,该步骤创建了具有多个测试用例执行的多个线程
...
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? 如何为每个执行获取隔离的作用域,以避免其他线程执行覆盖/设置测试用例变量?
I think you need to create a TC runner and then WsdlTestRunContext
. 我认为您需要先创建TC运行器,然后创建WsdlTestRunContext
。
I ran into similar situation where I needed to create a TC runner. 我遇到了类似的情况,需要创建TC运行程序。 Here . 在这里 。 I believe you can go one step further and create a context by using createContext(StringToObjectMap properties)
method of this WsdlTestCaseRunner
. 我相信您可以进一步使用此WsdlTestCaseRunner
createContext(StringToObjectMap properties)
方法创建上下文。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.