首页 > 解决方案 > Azure DevOps VsTest 多代理并行

问题描述

我将 Azure DevOps Server 2020 与自托管代理一起使用,并创建了一个 CI 管道,该管道在一个代理上并行执行我的所有测试。大约 5000 次测试(无 UI 测试)需要大约 7 分钟才能完成。太快了,我添加了 3 个额外的代理,将任务并行放入同一管道中的另一个作业: 4. 所有 4 个代理首先下载构建工件,然后运行一部分测试。但不幸的是,测试运行不是更快而是更慢,每个代理需要大约 8 分钟。

我的 1 个代理的 vstest yaml

- task: VSTest@2
  displayName: 'Run tests'
  inputs:
      testSelector: 'testAssemblies'
      testAssemblyVer2:
            **\*test*.dll
            !**\*TestAdapter.dll
            !**\*TestFramework.dll
            !**\obj\**
      searchFolder: '$(System.ArtifactsDirectory)'
      runInParallel: true
      codeCoverageEnabled: false
      rerunFailedTests: false

我的 4 个代理的 vstest yaml

- task: VSTest@2
  displayName: 'Run tests'
  inputs:
      testSelector: 'testAssemblies'
      testAssemblyVer2:
            **\*test*.dll
            !**\*TestAdapter.dll
            !**\*TestFramework.dll
            !**\obj\**
      searchFolder: '$(System.ArtifactsDirectory)'
      runInParallel: true
      codeCoverageEnabled: false
      distributionBatchType: 'basedOnExecutionTime'
      rerunFailedTests: false

我还尝试通过组装并根据测试数量+代理数量进行批处理,但似乎没有任何效果。

更奇怪的是,我有一个旧的基于 UI 的 CI 管道,在一个带有 4 个 TestCategories 的变量上具有多重配置和乘数,它分发了更多的测试 ~10000(我的也是 5000),但正如 TestCategory 提到的一样4 个代理(代理 1 上的 Cat1,代理 2 上的 Cat2 等等),最慢的一个在不到 4 分钟内完成。

基于 UI 的 yaml 如下所示:

steps:
- task: VSTest@2
  displayName: 'Run tests'
  inputs:
    searchFolder: '$(Build.BinariesDirectory)'
    testFiltercriteria: 'TestCategory=$(Tests)'
    runInParallel: true
    codeCoverageEnabled: false

我想我必须遗漏一些明显的东西。

提前致谢!

编辑1:

我使用 RDP 连接到我的代理,并且在任务管理器中有多个 testhost.x86 实例正在运行,最多同时运行 8 个,但不是一直运行。如果我在本地开始我的测试,那么 testhost.x86 的 8+ 个实例几乎一直都在运行,并且很少消失。如果这有任何帮助。

标签: unit-testingazure-devopscontinuous-integrationjobsmulti-agent

解决方案


推荐阅读