【发布时间】:2021-01-05 17:36:41
【问题描述】:
我们有超过 20 个程序集,我们需要通过将它们分成 2 个组来运行单元测试,这些组在 2 个不同的 VMS 上运行。两个虚拟机相互独立并并行运行。但是,VM 中的测试按顺序运行并且需要很长时间才能完成(我们有很多 UT)。 像这样的:
- job: UnitTests1
timeoutInMinutes: 50
pool:
vmImage: $(hostedPool)
steps:
- template: ./templates/run-unittests.yml
parameters:
artifactName: $(buildArtifact)
testAssemblies: ['assembly1', 'assembly2', 'assembly3', 'assembly4', 'assembly5', 'assembly6', 'assembly7', 'assembly8', 'assembly9', 'assembly10']
runName: UnitTest1
- job: UnitTests2
timeoutInMinutes: 35
pool:
vmImage: $(hostedPool)
steps:
- template: ./templates/run-unittests.yml
parameters:
artifactName: $(buildArtifact)
testAssemblies: ['assembly11', 'assembly12', 'assembly13', 'assembly14', 'assembly15', 'assembly16', 'assembly17', 'assembly18', 'assembly19', 'assembly20']
runName: unitTest2
run-unittests.yml
- ${{ each testAssembly in parameters.testAssemblies }}:
- task: VSTest@2
displayName: 'UT: ${{ testAssembly }}'
inputs:
vsTestVersion: toolsInstaller
testAssemblyVer2: |
$(Pipeline.Workspace)\${{ parameters.artifactName }}\**\MyProject.${{ testAssembly }}.Tests.dll
runSettingsFile: build/default.runsettings
runInParallel: false
runOnlyImpactedTests: false # Test Impact Analysis was evaluated and returns incorrect results
codeCoverageEnabled: true # collect code coverage
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
default.runsettings 用于测试
<!-- Configurations that affect the Test Framework -->
<RunConfiguration>
<MaxCpuCount>1</MaxCpuCount>
<TargetPlatform>x64</TargetPlatform>
<ParallelizeAssemblies>false</ParallelizeAssemblies>
<ParallelizeTestCollections>false</ParallelizeTestCollections>
如何启动多个线程/进程以在 1 个 VM 中并行运行这些 UT。 runInParallel 似乎什么也没做。
【问题讨论】:
-
你能显示
./templates/run-unittests.yml吗? -
我添加了更多细节。标志 runInParallel 似乎没有做任何事情
-
您的虚拟机有多个内核?您在 run.settings 文件中限制并行性?
-
@Matt,Azure Devops 提供给我们的代理。我们不拥有它们; Azure DevOps 使它们可供我们使用。 AFAIK 我们无法更新机器上的内核数量,因为我们不拥有它们,但我认为它们将是多核机器。
标签: azure-devops nunit azure-pipelines azure-pipelines-release-pipeline azure-pipelines-build-task