Daily Usage Issues

Debug covering tests not catching StackOverflowException

Started by johnmwright on 9,256 views

If a unit tests ends up generating a StackOverflowException, and I run that test using the "Debug covering test in new task runner process" NCrunch context menu option, when the exception occurs, the debug process just ends. It would be preferred if the debugger paused at the instance of the exception, or otherwise provided some meaningful feedback regarding the exception.

For reference, the NCrunch Tests window shows this text for the tests generating StackOverflows:
NCrunch was unable to retrieve a meaningful result from this test due to an unexpected error - was the execution process terminated?
I'm not sure how much can be done to change this behaviour (the CLR is very strict in how it handles stack overflows, and there are limited points of interception). Do you experience the same behaviour if you set the 'Use hosted task runner' global NCrunch configuration setting to 'False'?
To reproduce, I'm using the following NUnit test fixture:

[TestFixture]
public class Temp
{
[Test]
public void StackOverflowTest()
{
StackOverflowTest();
}
}

Note: you'll have to run it once with the self-referencing call commented out for NCrunch to show the context menus.

When running 'debug covering test in new runner' with 'use hosted task runner' set to True, I get almost no feedback, with control returning back to Visual Studio in edit mode.
With 'use hosted task runner' set to False, the VS debugger does pause when the exception occurs, but is unable to determine the stack location, as seen in this screenshot:
http://imgur.com/rwAbB

For comparision, what I would love to see is that the full stack and source code location of the exception is available in the VS debugger. This is the behavior seen when I use ReSharper's unit test runner in debug mode for the same test, as seen in this screenshot:
http://imgur.com/IGetd

Of course, I have no insight as to how ReSharper does this, or even how you do it, so have absolutely no idea on how to achieve this. :-)
One short-term nice-to-have would be to have the ncrunch test failure message note that a stackoverflow occurred, as this this would help narrow down where to start troubleshooting.


Note: I'm using VS2012 Beta, NCrunch 1.40.0.23b, Resharper 7 Beta, Nunit 2.5.10
NCrunch 1.40b did introduce a certain level of handling for stack overflows, though this doesn't seem to be working reliably and at this stage I have no information on how to properly improve it.

I'll need to keep this issue on the backlog until I can find a smarter way of handling it that will work reliably. Thanks for the detailed information, hopefully in future it will be handled in a cleaner way.

Post a reply

Log in to reply.