Partager via


Race Troubleshooting Using The Console Output In VSTS

It must be my week of discovering the obvious. The other day I was troubleshooting a race condition in my code. I had a unit test that faithfully reproduced the error, but just looking at the code involved didn't produce any sudden insights into its reasons. The nasty thing about race conditions (and multi-threaded code in general) is that you can't debug them, since the debuger influences the race.

Sometimes, you can troubleshoot race conditions by tracing strategic points in the code, and sometimes it doesn't work, since even tracing statements influence the race. In my particular case, tracing didn't disrupt my race condition, so the only problem left was how I could view that output as easily as possible. Since I was using VSTS unit tests from within Visual Studio 2005, I was hoping my Console output would be in the Output window, but no such luck. Then, in a rare case of inspiration, I double-clicked on the test in the Test Results window and got a window similar to this one (which is a mock-up, I admit):

Notice the highlighted Standard Console Output.

It's so simple that I wonder I never discovered this feature before, but now that I know it exists, I know how to troubleshoot race conditions reproduced in unit tests the next time I have to deal with multi-dreaded code :)

Comments

  • Anonymous
    October 06, 2007
    PingBack from http://www.artofbam.com/wordpress/?p=5757

  • Anonymous
    August 13, 2008
    The comment has been removed

  • Anonymous
    August 13, 2008
    Hi Roey Thank you for your question. The answer is both yes and no. While the Console API allows you to define color (e.g. via Console.ForegroundColor), there's no guarantee that the console sink will pick it up. Both the Command Prompt and PowerShell respect and display the color defined via the API, but VS, unfortunately, does not. So your best option is probably resorting to indentation, special characters, and/or upper case.

  • Anonymous
    December 03, 2012
    Cool! Thanks! I was wondering where the obvious was...