VS 2010 测试运行器错误“测试运行时代理进程已停止。”

发布于 2024-09-01 06:44:58 字数 470 浏览 2 评论 0原文

在 Visual Studio 2010 中,我进行了许多单元测试。当我使用测试列表一次运行多个测试时,有时会收到一个或多个测试的以下错误:

代理进程已停止 测试正在运行。

永远不会有相同的测试失败,如果我尝试再次运行测试,它就会成功。

我发现了这个关于 Connect 的错误报告,其中似乎是同样的问题,但它没有提供解决方案。

还有其他人看到过这种行为吗?我怎样才能避免它?

编辑

我仍然遇到这个错误,我的许多同事在相同的软件/硬件设置上也是如此。到目前为止,我已经评估了答案,但它们并没有解决问题。我正在开始悬赏解决这个问题。

In Visual Studio 2010, I have a number of unit tests. When I run multiple tests at one time using test lists, I sometimes reveive the following error for one or more of the tests:

The agent process was stopped while
the test was running.

It is never the same test failing, and if I try to run the test again, it succeeds.

I found this bug report on Connect, which seems to be the same problem, but it does not offer a solution.

Has anyone else seen this behaviour ? How I can avoid it ?

Edit

I am still experiencing this bug, and so is many of my colleagues on the same software/hardware setup. I have evaluated the answers so far, but they don't resolve the problem. I am starting a bounty for a solution to this problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(19

余厌 2024-09-08 06:44:58

此消息是由与执行测试线程不同的线程上的异常引起的。到目前为止,所有答案都归结为这个简单的解释。在这种情况下,Visual Studio 中的一个已知错误不会显示任何有意义的信息。

如果执行测试线程之外的线程抛出异常,Visual Studio 的测试运行程序将完全卡住:它被吞没,没有输出,没有机会拦截和调试,除了本应是你的单元的烧毁的闷烧混乱之外,什么也没有。测试。

This message is caused by an exception on a thread different from the executing test thread. All answers so far boil down to this simple explanation. It is a known bug in Visual Studio not to display any sensible information in that case.

Visual Studio’s test runner totally chokes if a thread other than the executing test thread throws an exception: It gets swallowed and there’s no output, no chance to intercept and debug and no nothing except a burned-down smoldering mess that was supposed to be your unit test.

夏雨凉 2024-09-08 06:44:58

我刚刚经历过类似的问题:一些测试失败,并且在不同的测试运行中它们是不同的。我不知道它发生的确切原因,但当我向我的一个类添加终结器时,它就开始发生。当我禁用终结器时 - 问题就消失了。当我打开终结器时 - 问题又回来了。

现在我不知道如何克服这个问题。

I've just experienced the similar problem: some tests fail and they are different in different test runs. I don't know exactly the reason why it happens, but it began to occur when I added a finalizer to one of my classes. When I disable the finalizer - the problem disappears. When I turn the finalizer on - the problem comes back.

Right now I don't know how to overcome this.

緦唸λ蓇 2024-09-08 06:44:58

我遇到了这个问题,结果证明这是我的代码中的问题,测试框架没有正确捕获。一次意外的重构给我留下了这段代码:

public void GetThingy()
{
    this.GetThingy();
}

这当然是一个无限递归,并导致了 StackOverflowException (我猜)。这导致了可怕的情况:“测试运行时代理进程被停止。”

快速的代码检查向我显示了问题,并且我的测试现在运行良好。希望这会有所帮助 - 可能值得检查代码以查找问题,或者可能提取一些内容到控制台应用程序中并检查它是否正常工作。

I was having this problem, and it turned out to be a problem in my code which the Test Framework wasn't catching properly. A little accidental refactoring had left me with this code:

public void GetThingy()
{
    this.GetThingy();
}

This is of course an infinite recursion, and caused a StackOverflowException (I guess). What this caused was the dreaded: "The agent process was stopped while the test was running."

A quick code inspection showed me the problem, and my tests are now running fine. Hope this helps - might be worth inspecting the code looking for issues, or maybe extracting a bit into a console app and checking it works properly there.

嘿哥们儿 2024-09-08 06:44:58

我能够通过查看测试结果文件(/TestResults/*.trx)找到问题的根源,它提供了后台线程中发生的异常的完整详细信息,一旦我解决了该异常,“代理已处理”停止了...”错误消失了。

就我而言,我无意中在单元测试中启动了 GUI,这最终导致抛出 System.ComponentModel.InvalidAsynchronousStateException。

所以我的 .trx 文件包含:

   <RunInfo computerName="DT-1202" outcome="Error" timestamp="2013-07-29T13:52:11.2647907-04:00">
    <Text>One of the background threads threw exception: 
System.ComponentModel.InvalidAsynchronousStateException: An error occurred invoking the method.  The destination thread no longer exists.
at System.Windows.Forms.Control.WaitForWaitHandle(WaitHandle waitHandle)
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at System.Windows.Forms.Control.Invoke(Delegate method)
...
</Text>
  </RunInfo>

这没有提供有关哪个测试导致错误的任何信息,但它确实向我显示了异常在哪里,这非常有用。

I was able to find the source of my problem by looking in the test result file (/TestResults/*.trx) It provided the full details of the exception that occurred in the background thread, and once I resolved that exception the "agent processed stopped..." error went away.

In my case I was unintentionally launching the GUI in my unit test, which eventually caused a System.ComponentModel.InvalidAsynchronousStateException to be thrown.

So my .trx file contained:

   <RunInfo computerName="DT-1202" outcome="Error" timestamp="2013-07-29T13:52:11.2647907-04:00">
    <Text>One of the background threads threw exception: 
System.ComponentModel.InvalidAsynchronousStateException: An error occurred invoking the method.  The destination thread no longer exists.
at System.Windows.Forms.Control.WaitForWaitHandle(WaitHandle waitHandle)
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at System.Windows.Forms.Control.Invoke(Delegate method)
...
</Text>
  </RunInfo>

This didn't provide any information on what test caused the error, but it did show me where the exception was, which was very useful.

可爱咩 2024-09-08 06:44:58

此消息通常在测试进程崩溃时生成,并且在后台线程上存在未处理的异常、发生堆栈溢出或显式调用 Process.GetCurrentProcess().Kill() 时可能会发生或Environment.Exit。另一个可能的原因是非托管代码中的访问冲突。

没有人提到的是事件日志中可能还有其他信息。通常,您不会在结果中获得有关测试崩溃原因的太多信息,但是,如果后台线程上出现未处理的异常,则测试框架会使用源 VSTTExecution 将详细信息写入应用程序事件日志。如果没有信息写入事件日志,则可能是上面列出的其他原因之一。

This message is typically generated when the test process crashes and can happen when there is an unhandled exception on a background thread, a stack overflow occurs, or an explicit call to Process.GetCurrentProcess().Kill() or Environment.Exit. Another possible cause is an access violation in unmanaged code.

Something no one has mentioned is that there may be additional information in the event log. Usually you will not get much information on why the test crashed in the results, however in the event of an unhandled exception on a background thread, then the test framework writes details to the Application event log with source VSTTExecution. If there is no information written to the event log then it is likely one of the other causes listed above.

焚却相思 2024-09-08 06:44:58

我遇到了同样的问题并在删除时解决了它,

Environment.Exit(0);

所以我很确定,当您的测试或测试方法被测试时,会发生此错误,导致执行过程终止。

I encountered the same Problem and solved it while Removing

Environment.Exit(0);

So i am pretty sure, that this error occurs while your test or method under test, is causing the executing process to terminate.

╰沐子 2024-09-08 06:44:58

就我而言,解决方案是通过检查输出窗口解决的。

“QTAgent32.exe”(托管
(v4.0.30319)): 已加载
'C:\TestResults\bdewey_XXXXXX072
2011-01-11
17_00_40\Out\MyCode.dll',
符号已加载。 E, 9024, 9,
2011/01/11, 17:00:46.827,
XXXXX072\QTAgent32.exe,未处理
异常捕获,报告通过
Watson:[异常消息]

就我而言,我有一个 FileSystemWatcher 在单独的线程上抛出错误。

In my case the solution was resolved by checking the Output Window.

'QTAgent32.exe' (Managed
(v4.0.30319)): Loaded
'C:\TestResults\bdewey_XXXXXX072
2011-01-11
17_00_40\Out\MyCode.dll',
Symbols loaded. E, 9024, 9,
2011/01/11, 17:00:46.827,
XXXXX072\QTAgent32.exe, Unhandled
Exception Caught, reporting through
Watson: [Exception message]

In my case I had a FileSystemWatcher that was throwing an error on a seperate thread.

永言不败 2024-09-08 06:44:58

感谢您发布问题。我刚刚遇到这个问题并找出了您可能遇到的原因。

异步异常可能有
发生了

在我的测试设置期间,我创建了一个对象,该对象在线程池中对工作线程进行排队。如果我足够快地进行调试,我的代码就会通过。

如果工作线程启动并在测试设置完成之前出现错误,那么我会毫无理由地得到中止结果。

如果工作线程启动并在测试开始后出现错误,那么我会得到以下结果:错误 - 测试运行时代理进程已停止。

需要注意的是:这是我在多次测试中使用的组件。如果测试框架遇到太多此类错误,它将中止其余测试。

希望这有帮助

Thanks for posting the question. I just ran into this problem and figured out a cause that you may be running into.

An asynchronous exception may have
occurred

During my test setup, I create an object that queues a worker thread in the thread pool. If I run through debugging fast enough my code passes.

If the worker thread kicks off and has an error BEFORE the test setup completes, then I get a result of Aborted with no reasoning.

If the worker thread kicks off and has an error AFTER the test has begun, then I get a result of : Error - The agent process was stopped while the test was running.

Important to note: this is a component that I use throughout several of my tests. If the test framework encounters too many of these errors it aborts the rest of the tests.

Hope this helps

别把无礼当个性 2024-09-08 06:44:58

我向析构函数 ~ClassName(){} 添加了 try/catch 块,该析构函数在我的测试中涉及的任何类中定义。这解决了我的问题。

~MyClass()
{
    try
    {
        // Some Code
    }
    catch (Exception e)
    {
        // Log the exception so it's not totally hidden
        // Console.WriteLine(e.ToString());
    }
}

I added try/catch blocks to the descructor ~ClassName(){} that were defined in any class involved in my tests. This fixed the problem for me.

~MyClass()
{
    try
    {
        // Some Code
    }
    catch (Exception e)
    {
        // Log the exception so it's not totally hidden
        // Console.WriteLine(e.ToString());
    }
}
乖乖 2024-09-08 06:44:58

要找出引发异常的位置,请单击“测试结果”窗口中感叹号图标旁边的超链接“测试运行错误”。将打开一个带有堆栈跟踪的窗口。

这对于追踪错误有很大帮助!

For finding out where the exception was thrown click on the hyperlink "Test Run Error" next to the exclamation icon in the Test Results window. A window with the stack trace is opened.

This helps a lot to track down the error!

漫雪独思 2024-09-08 06:44:58

我遇到了同样的问题,它是由非托管资源的终结器引起的(由于某种原因未正确处理的文件编写器)。

将终结器代码包装在吞掉异常的 try-catch 中后,问题就消失了。我不建议吞掉这样的异常,因此首先找出异常发生的原因显然是明智的。

I had the same problem and it was caused by a finalizer for an unmanaged resource (a file writer that was not getting disposed properly for some reason).

After wrapping the finalizer code in a try-catch that swallows the exception, the problem disappeared. I don't recommend swallowing exceptions like that, so it would obviously be wise to find out why the exception is occurring in the first place.

2024-09-08 06:44:58

我曾在奇怪的场合发生过这种情况,而罪魁祸首几乎总是被证明是线程。

奇怪的是,所有测试在开发机器上都能正常工作,但在构建服务器上却随机失败。

仔细检查后发现,尽管测试在开发盒上被列为已通过,但还是抛出了异常。异常是在一个单独的线程上抛出的,该线程没有被视为错误。

异常详细信息是针对测试跟踪记录的,因此我们能够识别需要修改哪些代码/测试。

希望这对某人有帮助。

I have had this happening on the odd occasion, and the culprit almost always turns out to be threading.

Strangely enough all the tests would work fine on the development machines, then randomly fail on the build servers.

On closer inspection it turned out that although the tests were being listed as passed on the dev boxes, there were exceptions being thrown. The exceptions were being thrown on a seperate thread which didn't get picked up as an error.

The exception details were being logged against the test trace, so we were able to identify which code/tests needed to be modified.

Hope this helps someone.

你的他你的她 2024-09-08 06:44:58

就我而言,我对 WCF 服务进行了一些单元测试。此 WCF 服务正在启动 2 个计时器。
这些计时器造成了副作用。
-->我默认禁用这些计时器,一切都很好!

顺便说一句:我使用 WCFMock 来伪造 WCF 服务,因此我对 WCF 服务进行了“真正的”单元测试

In my case I had some unit-tests for a WCF-service. This WCF service was starting up 2 timers.
Those timers caused side effects.
--> I disable these timers by default and everything is fine!

BTW: I use WCFMock to fake the WCF service, so I have "real" unit tests around my WCF service

不及他 2024-09-08 06:44:58

这个错误也是由我的终结器引起的。
Finalizer 实际上调用了一些未模拟的数据库代码。我花了一段时间才找到它,因为它不是我写的类,而且对它的引用被隐藏在相当多的类中。

This error was caused by a Finalizer for me as well.
The Finalizer was actaully calling some DB code which wasn't mocked out. Took me a while to find it as it wasn't a class I wrote and the reference to it was burred quite a few classes deep.

终遇你 2024-09-08 06:44:58

我遇到了类似的问题,测试在 TestInitialize 中失败,并且还从我的另一个项目的 ddl 运行代码。我收到如上所述的错误消息,如果我尝试调试测试,测试就会中止,没有任何异常详细信息。

我怀疑问题可能是我的其他项目中的 dll 来自 Visual Studio 2012 项目,而我正在 VS2010 项目中运行测试,和/或可能是这两个项目中的 UnitTestFramwork dll 版本不匹配。

I have run into a similar problem where a test is failing in TestInitialize and is also running code from a ddl from another of my projects. I get the error message as described above and if I try to debug the test, the test is just aborted without any exception details.

I suspect that the problem may be that the dlls from my other project are from a Visual Studio 2012 project and I am running my tests in a VS2010 project, and/or possibly that the UnitTestFramwork dll versions from the 2 projects are mismatched.

剩余の解释 2024-09-08 06:44:58

该问题也可能由 TestClass 构造函数中的异常或 Stackoverflow 触发。

The problem can also be triggered by an Exception or Stackoverflow in Constructor of a TestClass.

趴在窗边数星星i 2024-09-08 06:44:58

由于此错误可能有许多不同的原因,因此我想添加另一个错误以确保该线程的完整性。

如果您的所有测试都按照 OP 的描述中止,则原因可能是项目配置错误。在我的例子中,目标框架设置为 .NET Framework 3.5。通过项目属性页面(选项卡应用程序)将其设置为更高版本解决了该问题。

As this error can have many different causes, I'd like to add another one for completeness of this thread.

If all your tests are aborting as described by the OP, the cause might be a wrong project configuration. In my case the target framework was set to .NET Framework 3.5. Setting it to a higher version through the project properties page (tab Application) resolved the issue.

初雪 2024-09-08 06:44:58

通过查看Windows 日志>,我能够确定导致问题的原因。 Windows 事件查看器中的应用程序日志条目。查找测试失败时的条目。我有一个类似于下面的 Error 条目:

QTAgent32_40.exe, PID 10432, Thread 2) AgentProcess:CurrentDomain_UnhandledException: IsTerminating : System.NullReferenceException: Object reference not set to an instance of an object.
   at XXX.YYY.ZZZ.cs:line 660
   at XXX.YYY.AAA.Finalize() in C:\JenkinsSlave\workspace\XXX.YYY.AAA.cs:line 180

它确实是从类终结器调用的方法中的空引用异常。

I was able to determine what was causing my issue by looking in the Windows Logs > Application log entries within the Windows Event Viewer. Look for entries at the time the test bombed-out. I had an Error entry similar to below:

QTAgent32_40.exe, PID 10432, Thread 2) AgentProcess:CurrentDomain_UnhandledException: IsTerminating : System.NullReferenceException: Object reference not set to an instance of an object.
   at XXX.YYY.ZZZ.cs:line 660
   at XXX.YYY.AAA.Finalize() in C:\JenkinsSlave\workspace\XXX.YYY.AAA.cs:line 180

It was indeed a null reference exception within a method called from a class finalizer.

や莫失莫忘 2024-09-08 06:44:58

对于任何遇到这个老问题并想知道他们的线程中抛出了什么的人,这里有一个提示。使用Task.Run(而不是Thread.Start)将更可靠地报告子线程异常。简而言之,而不是这样:

Thread t = new Thread(FunctionThatThrows);
t.Start();
t.Join();

这样做:

Task t = Task.Run(() => FunctionThatThrows());
t.Wait();

并且您的错误日志应该更有用。

For anyone happening upon this old question and wondering what's being thrown from their thread(s), here's a tip. Using Task.Run (as opposed to, say, Thread.Start) will report child thread exceptions much more reliably. In short, instead of this:

Thread t = new Thread(FunctionThatThrows);
t.Start();
t.Join();

Do this:

Task t = Task.Run(() => FunctionThatThrows());
t.Wait();

And your error logs should be much more useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文