简体   繁体   English

如何在并行运行的不同SoapUI测试用例实例中获得单独的上下文?

[英]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.

相关问题 如何在Java中并行执行具有不同输入的方法的多个实例? - How to execute multiple instances of a method with different inputs in parallel in java? 并行循环以不同的间隔运行 - Parallel loops running at different intervals 如何获取线程池中当前并行运行的AsyncTask的总数? - How to get the total number of AsyncTasks currently running in parallel in the thread pool? 如何获取在Harmony中运行的Multiple Threading.Timer实例 - How to get Multiple Threading.Timer instances Running in Harmony 并行运行多个ANTLR4词法分析器/解析器实例 - Running multiple ANTLR4 lexer/parser instances in parallel 通过JButton动作侦听器并行运行的Perl脚本的多个实例 - Multiple instances of perl script running in parallel via JButton action listener 如何在 C++ 中并行处理类的实例? - How to process instances of classes in parallel in C++? 通过新的任务并行库,如何确保两个任务在不同的线程甚至不同的处理器上运行? - How can I ensure two tasks are running on different threads or even different processors with the new Task Parallel Library? 如何在 Java 中运行类的不同实例的线程之间同步静态变量? - How to synchronize a static variable among threads running different instances of a class in Java? 将两种形式作为不同的线程运行(或至少两种形式以“并行”方式运行) - Running two forms as different threads (or al least 2 forms running “parallel”)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM