unit-testing - 当执行单元测试步骤时以前工作的 VSTS 构建超时时,如何将更好的日志记录添加到调试中
问题描述
我有一个带有单元测试的 VSTS 构建,以前在 VSTS 构建中工作过。本周,由于超时而停止工作。
由于 60 分钟后超时而发生故障。以下是我们所知道的:
- 测试库仅包含 1 个测试。我们通过指向 VSTS 的单元测试配置中的测试程序集来运行测试。
- 测试仍然在本地工作(在 <1 秒内运行)。
- 即使我删除了实际测试并用一个只检查 Assert.IsTrue(true) 的简单测试替换它,测试仍然超时。因此,我们得出结论,导致问题的原因是测试配置,而不是测试本身。
- 我尝试向测试添加额外的调试日志记录,但似乎测试执行从未真正开始。
- 似乎没有生成 trx 日志文件。它似乎根本没有真正尝试运行测试。
- 我们已经在 VSTS 托管的 VM 和我们自己的 VM 上进行了尝试,结果相同。
- 我们尝试在构建中添加一个新的测试步骤,并指出测试 DLL 没有对默认值进行其他修改,但它仍然卡住。
- 我们将原始测试步骤指向不同的测试 DLL,测试通过了!所以与这个特定的库相关的东西是不同的(但同样,即使我删除了所有测试它仍然会卡住)。
有没有人对其他事情有其他建议来尝试缩小可能导致这种情况的范围(例如,VSTS 中的跟踪日志记录)?下面的日志文件显示了我们单元测试配置的一些细节,但如果其他细节有帮助,请告诉我。
失败日志如下所示:
> ============================================================================== 2018-07-18T20:14:25.1963123Z Run the tests locally using
> vstest.console.exe 2018-07-18T20:14:25.1964566Z
> ======================================================== 2018-07-18T20:14:25.1965645Z Test selector : Test assemblies
> 2018-07-18T20:14:25.1966925Z Test assemblies : **\<PathToTestLib>.dll
> 2018-07-18T20:14:25.1968187Z Test filter criteria : null
> 2018-07-18T20:14:25.1968810Z Search folder : C:\vsts-agent\_work\4\s
> 2018-07-18T20:14:25.1969311Z Run settings file :
> C:\vsts-agent\_work\4\s 2018-07-18T20:14:25.1970327Z Run in parallel :
> false 2018-07-18T20:14:25.1970792Z Run in isolation : false
> 2018-07-18T20:14:25.1972913Z Path to custom adapters : null
> 2018-07-18T20:14:25.1973153Z Other console options : null
> 2018-07-18T20:14:25.1973381Z Code coverage enabled : false
> 2018-07-18T20:14:25.1974004Z Rerun failed tests: false
> 2018-07-18T20:14:25.1974423Z VisualStudio version selected for test
> execution : latest 2018-07-18T20:14:25.3811086Z
> ======================================================== 2018-07-18T20:14:30.6014691Z [command]"C:\Program Files
> (x86)\Microsoft Visual
> Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"
> @C:\vsts-agent\_work\_temp\2aa40f41-8ac7-11e8-b190-a1cdff2b8b30.txt
> 2018-07-18T20:14:30.8198002Z Microsoft (R) Test Execution Command Line
> Tool Version 15.7.2 2018-07-18T20:14:30.8206458Z Copyright (c)
> Microsoft Corporation. All rights reserved.
> 2018-07-18T20:14:30.8206862Z 2018-07-18T20:14:30.8227447Z
> vstest.console.exe 2018-07-18T20:14:30.8228082Z
> "C:\vsts-agent\_work\4\s\partners\exooutlook\OutlookAnalysisSolution.Test\bin\Debug\OutlookAnalysisSolution.Test.dll"
> 2018-07-18T20:14:30.8228647Z /logger:"trx"
> 2018-07-18T20:14:31.0672644Z Starting test execution, please wait...
> 2018-07-18T21:14:05.8979923Z ##[error]The operation was canceled.
> 2018-07-18T21:14:05.9027909Z ##[section]Finishing: Unit Tests
解决方案
我们找到了挂起的根源。它位于标有“AssemblyInitialize”属性的测试类方法中。
[TestClass]
public class TestClassInitializer
{
[AssemblyInitialize]
public static void AssemblyInit(TestContext context)
{
LocalResourceDeployment.CopyResources();
}
}
CopyResources() 中存在一个错误,该错误未在本地显示,但导致 VSTS 中的 powershell 窗口等待控制台输入。
我们已经改进了这个初始化方法中的跟踪日志记录,这样如果将来它再次失败,我们至少会有一个指向测试卡住的地方的指针。例如:
Trace.WriteLine("Starting test assembly initializtion.");
推荐阅读
- javascript - 如何实现具有动态状态数的 Context API?
- python - python - 如何将每行的单词转换为由'::'分隔的数组,并将每一行转换为Python中的不同数组?(存储在文件中。)
- postgresql - pg_get_serial_sequence 返回错误:关系“---”的列“---”不存在
- python - 在 3D 曲面图中绘制 DataFrame
- ios - 在 Swift 中使用 MKLocalSearch 将 pin 附加到用户位置而不是蓝点
- agda - 此错误中提到的解析错误是什么?
- c# - ML-Agents agent not resetting?
- git - Is git push --force-with-lease always safe?
- node.js - ec2 实例上的 Nginx 不提供静态文件
- ssh - VSCode Remote-SSH 无法连接