Specflow 项目构建“由于 StackOverflowException 而终止”

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

我们的 Specflow 项目开始构建失败,并显示“由于 StackOverflowException,进程已终止”。

我能够将测试项目缩减为只有一个功能文件,如下所示:

Feature: PDBSPCTK Get Availability groups (Avgpad) - Tux

Scenario: Get availability groups JSON
Given I create the following "Avgpad" class and save it as "Avgpad"
Then I verify the "Response_Avgpar" object contains the following data
"""
LARGE JSON DATA
"""

Below is the build output:

Build started at 10:51 AM...
1>------ Build started: Project: TestAutomation, Configuration: Debug Any CPU ------
1>  SpecFlowFeatureFiles: PDBSPCTK\ACSR\Avgpad\Tux\GetAvgpadTux.feature;PDBSPCTK\psRetrieveCCSAccountAndCustomerByUD\Db\RetrieveCCSAccountAndCustomerByUD.feature;PDBSPCTK\psRetrieveCCSAccountAndCustomerByUD\Tux\RetrieveCCSAccountAndCustomerByUD.feature
1>  SpecFlowGeneratedFiles: PDBSPCTK\ACSR\Avgpad\Tux\GetAvgpadTux.feature.cs
1>  SpecFlowGeneratedFiles: PDBSPCTK\psRetrieveCCSAccountAndCustomerByUD\Db\RetrieveCCSAccountAndCustomerByUD.feature.cs
1>  SpecFlowGeneratedFiles: PDBSPCTK\psRetrieveCCSAccountAndCustomerByUD\Tux\RetrieveCCSAccountAndCustomerByUD.feature.cs
1>  SourceRoot value was 'C:\Users\qiuw01\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\'
1>  SourceRoot value is 'C:\Users\qiuw01\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\;C:\Users\qiuw01\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\'
1>  SourceRoot.SourceControl is ''
1>  SourceRoot.MappedPath is 'C:\Users\qiuw01\.nuget\packages\'
1>  SourceRoot.MappedPath is 'C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\'
1>  SourceRoot.SourceLinkUrl is ''
1>C:\Users\qiuw01\.nuget\packages\microsoft.sourcelink.common\1.0.0\build\Microsoft.SourceLink.Common.targets(52,5): warning : Source control information is not available - the generated source link is empty.
1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(84,5): error : 
1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(84,5): error : Process is terminated due to StackOverflowException.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 10:51 AM and took 14.314 seconds ==========

附加信息:

  1. 堆栈溢出似乎与大型 JSON 数据的大小有关。一旦其大小减小,堆栈溢出就会停止发生。
  2. 上游包引入对 System.Text.Json 的依赖后,堆栈溢出开始发生。

所以我的问题是,对 System.Text.Json 的间接依赖如何导致 Specflow 对特征文件中的 JSON 数据大小敏感?

json stack-overflow specflow system.text.json
1个回答
0
投票

我可以报告我们的发现和解决方案。

  1. 进一步测试证明,这可能不是JSON解析问题,而是与嵌入的多行字符串的大小限制有关。如果嵌入的 JSON 的大小减少到小于 335,690 个字符,则构建成功。如果再添加一个字符使字符串变为 335,690,则会抛出 StackOverflowException。当用最多 335,690 个字符的随机文本替换嵌入的 JSON 时,可能会重现该问题。如果它保持在 335,689 个字符,则构建成功。
  2. 项目转SDK风格后,构建成功。因此,对 System.Text.Json 的新依赖可能会触发 SpecFlow 和旧式项目的一些奇怪的交互,从而导致 StackOverflowError。
© www.soinside.com 2019 - 2024. All rights reserved.