Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Exceptions in tasks
Sakari
#1 Posted : Friday, December 27, 2013 9:42:01 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/25/2013(UTC)
Posts: 3
Location: Belgium

Thanks: 1 times
My tests usually test client-server components.
A lot of these are started in a dummy thread and communicated to through a dummy network.
They are done shutdown "quickly", which means the server will simply stop what it's doing, close it's (dummy) sockets and exit.
This has as a side effect that some TPL tasks that the server has started might fail due to sockets no longer be available.

These errors are harmless as the .NET runtime doesn't consider exceptions in tasks to be fatal, they do however, cause ncrunch to consider my test to have failed.
is there a way to tell Ncrunch that TPL task exceptions are to be ignored ?

Remco
#2 Posted : Friday, December 27, 2013 10:50:15 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,986

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi, thanks for posting!

NCrunch's behaviour around background exception handling is specific to the test framework you're using. The framework itself decides what to do with the exception - in most cases reporting it in such a way that NCrunch will fail the test.

My understanding of the TPL is that exceptions can be pushed up to be handled by threads interacting with the Task objects. It may well be that they are being thrown in such a way that the component you are using doesn't know what to do with them.

I'm afraid that this is unlikely to be a problem that can be solved in the test runner itself. You'll need to take a look at the abstractions you're using to see if you can find a way to change the way your code is reporting exceptions on the background thread. You might find it useful to inject an exception handler in your test code that is intended to silently swallow any background exceptions that are thrown. This could be switched out in your production code to instead find a constructive way to log the exception or inform the user of it.

Background exceptions can actually be a huge risk to a runtime application in production, as the default behaviour from .NET 2.0 upwards is for the process to be torn down if an unhandled exception bubbles up on any thread. Although suddenly closing a server-side socket may not be typical for your application at production run-time, I think you'll find there are many advantages to adding extra hooks in this area to preserve the running state of your application.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.033 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download