Call to Console.WriteLine() crashes Visual Studio 2010 Load Test Agent

April 14, 2012

This doesn’t make a shred of sense to me but I’ve been working on running some MSTest unit tests as part of a Visual Studio 2010 Load Test on a VS2010 Load Test Rig and ran into a very weird problem.

Most of the unit tests behave perfectly when run as part of a load test but one kept causing problems.  When I’d run the load test I’d get an exception message saying “Error occurred running test.  Could not run load test ‘’ on agent ‘’: The given key was not present in dictionary.

SNAGHTMLf13a0a1

I’d get this exception message box a few times at the start of the load test and then the load test would abort.  So a load test that should take 3 minutes was aborting after maybe 15 seconds.

SNAGHTMLf161218

Basically, what was happening is that *something* in this unit test was causing the QTAgent32.exe process to crash.

When I’d look at the event log on the load test agent machine, I’d see a couple of different errors in the Application Log:

1. QTAgentService.exe logging an error saying “OutOfProcessStrategy.ProcessMonitorThread: Agent process was shut down unexpectedly; will attempt to restart”

2. QTAgent32.exe logging an error saying “The process was terminated due to stack overflow.”

Error Message #1

Log Name:      Application
Source:        VSTTAgent
Date:          4/12/2012 1:43:48 PM
Event ID:      0
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      WSPCTESTMAC13
Description:
(QTAgentService.exe, PID 2844, Thread 16) OutOfProcessStrategy.ProcessMonitorThread: Agent process was shut down unexpectedly; will attempt to restart
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">


0
2
0
0x80000000000000

70373
Application
WSPCTESTMAC13



(QTAgentService.exe, PID 2844, Thread 16) OutOfProcessStrategy.ProcessMonitorThread: Agent process was shut down unexpectedly; will attempt to restart

Error Message #2

Log Name:      Application
Source:        .NET Runtime
Date:          4/12/2012 1:43:48 PM
Event ID:      1027
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      WSPCTESTMAC13
Description:
Application: QTAgent32.exe
Framework Version: v4.0.30319
Description: The process was terminated due to stack overflow.

Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">


1027
2
0
0x80000000000000

70372
Application
WSPCTESTMAC13



Application: QTAgent32.exe
Framework Version: v4.0.30319
Description: The process was terminated due to stack overflow.


The Cause of the Problem

The unit tests that I was working on are making lots of WCF calls so at first, I spent a lot of time trying to diagnose possible problems with WCF.  The tests would execute just fine when they weren’t running as part of a load test and I ran them directly from the MSTest runner.  So, I was fairly confident that it wasn’t a problem with the logic.

Next, I started commenting out portions of the unit test so that I could see exactly where it was dying.  I don’t know how this is possible but I tracked the problem down to a Console.WriteLine() statement.  The flow of the code went something like this:

DoWcfServiceOperation1();
DoWcfServiceOperation2();
Console.WriteLine(); // BOOOM!!!!
DoWcfServiceOperation3();

Here’s the actual Console.WriteLine() that was causing the problem.

SNAGHTML1a08406

Unless I’m missing something, it’s a perfectly ordinary and correct Console.WriteLine() statement. When it’s there, the load test and the load test rig crashes. When it’s not there, everything works great.

I’m stumped.

So, I hope this helps someone out and if any of you have any clue why this would be happening, let me know.

-Ben

-- Having trouble with Visual Studio 2010 or Visual Studio 2012 Load Tests?  Want to know more about the new Visual Studio 2012 Load Test Project?  Need someone to see if your app can handle the pressure?  Drop us a line at info@benday.com.

Categories: visual-studio-2010
Tags: load-tests tdd