【发布时间】:2016-11-03 12:21:50
【问题描述】:
几天以来,我们在构建 TFS 时遇到了问题。我们在一些单元测试中使用 Microsoft Shims/Fakes,到目前为止我们没有遇到任何问题。 但最近 UnitTest 步骤失败并出现以下错误: 每隔一段时间就会发生以下情况:
2016-07-01T06:40:25.3532321Z ##[error]Error: System.IO.IOException: The process cannot access the file 'D:\Builds\Agent\87a4a39e\...\bin\Debug\mscorlib.4.0.0.0.Fakes.FakedTypesCache' because it is being used by another process.
2016-07-01T06:40:25.3532321Z ##[error] at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
2016-07-01T06:40:25.3532321Z ##[error] at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
2016-07-01T06:40:25.3532321Z ##[error] at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
2016-07-01T06:40:25.3532321Z ##[error] at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost)
2016-07-01T06:40:25.3532321Z ##[error] at System.IO.StreamReader..ctor(String path)
2016-07-01T06:40:25.3532321Z ##[error] at Microsoft.VisualStudio.TraceCollector.FakesAssemblyReflector.LoadShimTypesFromCache(String fakedTypesCacheFilePath)
2016-07-01T06:40:25.3532321Z ##[error] at Microsoft.VisualStudio.TraceCollector.FakesAssemblyReflector.ReflectShimTypes(String fakesAssemblyFullPath)
2016-07-01T06:40:25.3532321Z ##[error] at Microsoft.VisualStudio.TraceCollector.UnitTestIsolationDataCollector.PopulateCollectionPlan(_CollectionPlan plan, XmlElement settings)
2016-07-01T06:40:25.3532321Z ##[error] at Microsoft.VisualStudio.TraceCollector.UnitTestIsolationDataCollector.OnSecondCollectorToInitialize(_CollectionPlan plan, XmlElement configurationElement)
2016-07-01T06:40:25.3532321Z ##[error] at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.OnInitialize(XmlElement configurationElement)
2016-07-01T06:40:25.3532321Z ##[error] at Microsoft.VisualStudio.TraceCollector.BaseDataCollector.InternalConstruct(XmlElement configurationElement, IDataCollectionEvents events, IDataCollectionSink dataSink, IDataCollectionLogger logger, IDataCollectionAgentContext agentContext)
2016-07-01T06:40:25.3532321Z ##[error] at Microsoft.VisualStudio.TraceCollector.BaseDataCollector.Initialize(XmlElement configurationElement, DataCollectionEvents events, DataCollectionSink dataSink, DataCollectionLogger logger, DataCollectionEnvironmentContext environmentContext)
2016-07-01T06:40:25.3532321Z ##[error] at WEX.TestExecution.DataCollectorTestMode.Initialize(ITestModeSettings settings, ICallbackRegistrar callbackRegistrar)
2016-07-01T06:40:25.3532321Z ##[error]
我不确定它是否与我们的代码覆盖率有关(因为堆栈跟踪提到了这个数据收集器)。我们使用 runsettings 文件从代码覆盖范围内/排除某些内容。
在构建服务器上,我们安装了 Visual Studio 2015 Update 3(但问题也出现在 Update 2 中),并且 TFS 是 2015 RTM 版本。
明显被锁定的文件并不总是相同的,但它总是“FakeTypeCaches”之一。
任何帮助将不胜感激
谢谢
编辑
似乎问题是由并行运行单元测试引起的(我认为该选项自 VS 2015 Update 1 起可用)。不并行运行它们似乎已经解决了问题,但遗憾的是现在运行我们的测试需要更长的时间才能运行。特别是对于我们的 CI 构建来说,这并不理想,因为我们希望尽快获得反馈。 如果我们只能按顺序运行使用 Faked/Stubbed 类的测试,那将是理想的,但据我所知,我不知道如何实现这一目标。
我们现在解决此问题的解决方案是使用 TestCategory 标记所有使用 Fakes/Shims 的测试:[TestCategory("Sequential")]
在构建服务器上,我们定义了两个单元测试步骤,第一个过滤除“Sequential”之外的所有类别并并行运行,第二个然后不并行运行“Sequential”。
【问题讨论】:
-
您的构建服务器上是否有多个构建代理?如果您尝试使用另一个构建代理来构建它会产生什么结果?
-
您好,我们在构建服务器上只有一个构建代理。
标签: c# visual-studio tfs