如何在不同的 SoapUI 测试用例实例 运行 中并行获取单独的上下文?
How to get a separate context in different SoapUI testcase instances running in parallel?
我有一个带有 groovy 脚本测试步骤的 SoapUI 测试用例(名称 "create entity"
),它使用在上下文中接收的一些变量,例如计数器值,处理它和 returns 一些其他值,例如返回ID
// 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)
并且此测试用例是从另一个测试用例 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()
}
如何为每个执行获取一个独立的范围,以避免 overriding/setting 测试用例变量被其他线程执行?
我认为您需要创建一个 TC runner 然后 WsdlTestRunContext
。
我 运行 遇到了类似的情况,我需要创建一个 TC runner。 。我相信您可以更进一步,使用此 WsdlTestCaseRunner
的 createContext(StringToObjectMap properties)
方法创建上下文。
我有一个带有 groovy 脚本测试步骤的 SoapUI 测试用例(名称 "create entity"
),它使用在上下文中接收的一些变量,例如计数器值,处理它和 returns 一些其他值,例如返回ID
// 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)
并且此测试用例是从另一个测试用例 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()
}
如何为每个执行获取一个独立的范围,以避免 overriding/setting 测试用例变量被其他线程执行?
我认为您需要创建一个 TC runner 然后 WsdlTestRunContext
。
我 运行 遇到了类似的情况,我需要创建一个 TC runner。 WsdlTestCaseRunner
的 createContext(StringToObjectMap properties)
方法创建上下文。