IT story

VS 2010 테스트 실행기 오류 "테스트가 실행되는 동안 에이전트 프로세스가 중지되었습니다."

hot-time 2020. 8. 23. 09:59
반응형

VS 2010 테스트 실행기 오류 "테스트가 실행되는 동안 에이전트 프로세스가 중지되었습니다."


Visual Studio 2010에는 여러 단위 테스트가 있습니다. 테스트 목록을 사용하여 한 번에 여러 테스트를 실행할 때 때때로 하나 이상의 테스트에 대해 다음 오류가 발생합니다.

테스트가 실행되는 동안 에이전트 프로세스가 중지되었습니다.

동일한 테스트가 실패한 것은 아니며 테스트를 다시 실행하려고하면 성공합니다.

Connect 에서이 버그 보고서를 찾았 는데 동일한 문제인 것 같지만 해결책을 제공하지 않습니다.

이 행동을 본 사람이 있습니까? 어떻게 피할 수 있습니까?

편집하다

나는 여전히이 버그를 겪고 있으며, 같은 소프트웨어 / 하드웨어 설정을 사용하는 동료들도 많습니다. 지금까지 답변을 평가했지만 문제가 해결되지 않았습니다. 이 문제에 대한 해결책에 대한 현상금을 시작하고 있습니다.


방금 비슷한 문제가 발생했습니다. 일부 테스트는 실패하고 다른 테스트 실행에서 다릅니다. 왜 그런 일이 발생했는지 정확히 모르지만 클래스 중 하나에 종료자를 추가했을 때 발생하기 시작했습니다. 종료자를 비활성화하면 문제가 사라집니다. 파이널 라이저를 켜면 문제가 다시 발생합니다.

지금 나는 이것을 극복하는 방법을 모릅니다.


이 메시지는 실행중인 테스트 스레드와 다른 스레드예외 로 인해 발생 합니다 . 지금까지의 모든 답변은이 간단한 설명으로 요약됩니다. 이 경우 현명한 정보를 표시하지 않는 것은 Visual Studio의 알려진 버그입니다.

Visual Studio의 테스트 실행기는 실행중인 테스트 스레드 이외의 스레드가 예외를 throw하면 완전히 질식합니다. 삼켜지고 출력이없고, 가로 채고 디버그 할 기회가 없으며, 당신의 단위가되어야했던 불타 오르는 엉망진창을 제외하고는 아무것도 없습니다. 테스트.


이 문제가 발생했는데 내 코드에서 테스트 프레임 워크가 제대로 포착하지 못하는 문제로 판명되었습니다. 약간의 우발적 인 리팩토링으로 인해 다음 코드가 남았습니다.

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

이것은 물론 무한 재귀이며 StackOverflowException (내 생각에)이 발생했습니다. 이로 인해 "테스트가 실행되는 동안 에이전트 프로세스가 중지되었습니다."라는 두려움이 생겼습니다.

빠른 코드 검사를 통해 문제가 확인되었으며 이제 테스트가 정상적으로 실행되고 있습니다. 이것이 도움이되기를 바랍니다. 문제를 찾는 코드를 검사하거나 콘솔 앱으로 약간 추출하여 제대로 작동하는지 확인하는 것이 좋습니다.


테스트 결과 파일 (/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>

이것은 어떤 테스트가 오류를 일으켰는지에 대한 정보를 제공하지 않았지만 예외가 어디에 있는지 보여 주므로 매우 유용했습니다.


테스트 프로세스 충돌 및 배경 스레드에서 처리되지 않은 예외가있을 때 일어날 수있는 경우이 메시지는 일반적으로 생성, 스택 오버 플로우가 발생, 또는 명시 적으로 호출 Process.GetCurrentProcess().Kill()하거나 Environment.Exit. 또 다른 가능한 원인은 비 관리 코드의 액세스 위반입니다.

아무도 언급하지 않은 것은 이벤트 로그에 추가 정보가있을 수 있다는 것입니다. 일반적으로 테스트가 결과에서 충돌 한 이유에 대한 많은 정보를 얻지 못하지만 백그라운드 스레드에서 처리되지 않은 예외가 발생하는 경우 테스트 프레임 워크는 소스 VSTTExecution을 사용하여 응용 프로그램 이벤트 로그에 세부 정보를 기록합니다. 이벤트 로그에 기록 된 정보가 없으면 위에 나열된 다른 원인 중 하나 일 수 있습니다.


동일한 문제가 발생하여 제거하는 동안 해결했습니다.

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.


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


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.


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());
    }
}

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!


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.


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.


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


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.


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.


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


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.


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.

참고URL : https://stackoverflow.com/questions/2810012/vs-2010-test-runner-error-the-agent-process-was-stopped-while-the-test-was-runn

반응형