Howto resolve .net test hangs on “Starting test execution, please wait…”

我怕爱的太早我们不能终老 提交于 2019-12-04 05:24:21

The versioning was a red herring and it turned out to be much simpler problem. My tests were testing Async controller methods, and my non-async tests were doing:

var result = controller.PostAsync(request).Result;

as soon as I changed the tests themselves to use the async/await pattern they worked fine:

var result = await controller.PostAsync(request);

Something that helped me diagnose the issue was using the dotnet test --verbosity d argument. When using this it was outputting some tests that were passing rather than just "Starting test execution, please wait". Interestingly every time I run the command it would execute a different number of tests before appearing to get stuck. This suggested there was perhaps some sort of thread deadlock issue which led me to the solution. I'm still unsure why the command ran fine on my local machine but not our Jenkins slave.

Sometimes xUnit tests hang forever because the test runner pipeline can't handle parallel threads.

To check if that's the issue try adding xunit.runner.json file to the tests project root

  <ItemGroup>
    <None Update="xunit.runner.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

And put inside 1 thread config.

{
  "parallelizeTestCollections": true,
  "maxParallelThreads": -1
}

The solution that worked for me was to add an AssemblyInfo.cs file with the following contents:

using Xunit;

[assembly: CollectionBehavior(DisableTestParallelization = true)]

Once I did this, the tests started running in my CI builds again (in my case, Azure Pipelines).

Updating Microsoft.NET.Test.Sdk from 15.9 to 16.3 helped in csproj file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!