Azure Pipeline 集成测试无限期挂起(LocalDb 问题?)

问题描述 投票:0回答:1

我有一个用于集成测试的管道,它在没有太多信息的情况下挂起。两周前它起作用了,当我上周再次运行管道时,它没有起作用。

本地所有测试都非常有效。

我尝试过的事情:

  • 将我的代码和 pipeline.yml 回滚到上次工作时的相同提交
  • 开始测试之前设置 LocalDB
  • 在单独的 yml 任务中从 MSI 安装 SQL Express 版本
  • 从我使用的 ps 脚本运行测试
    Enter-VsDevShell
  • sqllocaldb info/stop/delete/start 都提供与我的本地计算机相同的版本
  • 从 mssqllocaldb 更改连接字符串 -> 会出现另一个错误
  • 在 windows-2019 而不是 windows-latest 上运行
  • 在调试构建配置中构建和测试
  • 使用publishRunAttachments测试任务:false
  • 添加了责备挂起,否则它将永远运行
  • 添加了 -p:ParallelizeTestCollections=false" 到
    dotnet test
    -命令
  • 添加了
    console;verbosity=detailed
    但我看不到任何额外的价值
  • 连接字符串中的 Server=(localdb)\mssqllocaldb
  • sqlcmd -l 60 -S "(localdb)\mssqllocaldb" -Q "SELECT @@VERSION;"
    正在工作
{
  "ConnectionStrings": {
    "StorageDbConnection": "Server=(localdb)\\mssqllocaldb;Database=StorageTestDb;Trusted_Connection=True;MultipleActiveResultSets=true",
  }
}
  <ItemGroup>
    <PackageReference Include="FluentAssertions" Version="6.10.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
    <PackageReference Include="Moq" Version="4.18.4" />
    <PackageReference Include="Respawn" Version="6.0.0" />
    <PackageReference Include="xunit" Version="2.4.2" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="3.2.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

来自 pipeline.yml 的原始任务:

- task: DotNetCoreCLI@2
  name: dotnetTest
  displayName: Running tests
  inputs:
    command: 'test'
    projects: '**/*Tests/*.csproj'
    arguments: '--no-build --configuration $(buildConfiguration) --logger "console;verbosity=detailed" --blame-hang --blame-hang-timeout 1min'
    publishTestResults: false

责备超时的堆栈跟踪:

The active test run was aborted. Reason: Test host process crashed
Data collector 'Blame' message: The specified inactivity time of 2 minutes has elapsed. Collecting hang dumps from testhost and its child processes.
Data collector 'Blame' message: Dumping 644 - testhost.

Attachments:
  D:\a\1\s\src\Storage\tests\Storage.Application.IntegrationTests\TestResults\7360506b-d062-4e10-8d30-8302c4b56dbd\testhost_644_20230707T081918_hangdump.dmp
  D:\a\1\s\src\Storage\tests\Storage.Application.IntegrationTests\TestResults\7360506b-d062-4e10-8d30-8302c4b56dbd\Sequence_fd411c6d094d49478d7ee506dc44ebfd.xml
Test Run Aborted with error System.Exception: One or more errors occurred.

 ---> System.Exception: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
 ---> System.Exception: An existing connection was forcibly closed by the remote host.
   at System.Net.Sockets.NetworkStream.Read(Span`1 buffer)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Span`1 buffer)
   at System.Net.Sockets.NetworkStream.ReadByte()
   at System.IO.BinaryReader.Read7BitEncodedInt()
   at System.IO.BinaryReader.ReadString()
   at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.LengthPrefixCommunicationChannel.NotifyDataAvailable()
   at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TcpClientExtensions.MessageLoopAsync(TcpClient client, ICommunicationChannel channel, Action`1 errorHandler, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---.
The active Test Run was aborted because the host process exited unexpectedly. Please inspect the call stack above, if available, to get more information about where the exception originated from.

我可以在管道上设置防火墙或权限吗?

有没有更好的方法来调试或查找实际超时的内容?

c# azure-pipelines .net-6.0 xunit localdb
1个回答
0
投票

终于成功了。也发现有人有类似的问题,但解决方案不同:https://github.com/actions/runner-images/issues/7683 我可能受到了 Windows 图像的相同更改的影响,我们的麻烦似乎是大约在同一时间开始的。

将管道任务更改为 VSTest 后,我得到了更多输出(在测试和测试设置中添加了 Console.WriteLine 调试行),我什至在进入测试用例之前就可以看到测试设置失败。

在我的数据库种子中,我有一个像

await SaveChangesAsync(cancellationToken);
这样的调用从未完成。我将其更改为
SaveChanges();
,管道开始工作。

不知道为什么它会起作用,可能是一些竞争条件,死锁之类的。在本地运行一直运行良好。

© www.soinside.com 2019 - 2024. All rights reserved.