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

Notification

Icon
Error

NCrunch Fails when running tests using async / await and tcp connections
s0127786
#1 Posted : Friday, June 7, 2013 9:22:48 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/7/2013(UTC)
Posts: 3

Hi All,

I'm relatively new to NCrunch and willing to believe this is something wrong with my setup but I'm running a fairly complex test which:

Creates a TCP Server and awaits new connections.
Creates a TCP Client and connects to the server
Establish an SSL connection between them using SSLStream (AuthenticateAsClient / Server respectively).

Verify that a connection has been established.

If I remove the AuthenticateAsClient / Server calls then the test completes with no problems.

If they're left in then intermittently I get a Windows error saying that ncrunch has stopped responding. A new process seems to spin up immediately though but in these cases the test will fail with:
NCrunch was unable to retrieve a meaningful result from this test due to an unexpected error - was the execution process terminated?

I've checked through the logs and nothing is jumping out at me related to that particular test. Firewall permits all ncrunch connections (and it doesnt seem to be the connection itself that's the problem).

Sorry this isn't more helpful, happy to run any tests that you might find useful.

Thanks,


Michael
Remco
#2 Posted : Friday, June 7, 2013 10:27:33 AM(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 Michael -

Thanks for sharing this issue. Socket/TCP/SSL tests are fairly routine for NCrunch, so I suspect that the devil here is in the detail of the code running under test.

By far the most common cause of test process termination is stack overflows. My first thought is that there may be some subtle difference in the NCrunch test environment (i.e. that changes test sequence or surfaces a race condition, etc), that is causing the code under test to behave differently and then exploding. Is it possible to cause the test to fail while you have a debugger attached? The big problem with stack overflows is that they tend to nuke the state of the test process, which makes it hard to get information without using the debugger.

Cheers,

Remco
s0127786
#3 Posted : Friday, June 7, 2013 11:01:50 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/7/2013(UTC)
Posts: 3

Thanks for the quick response.

I've submitted a bug report from inside visual studio which hopefully will include more detailed logs and it's good news that this *should* be working (means it's more likely we'll get it fixed).

I can't reproduce it outside of ncrunch but they pass fine both in normal mode and debug mode using the regular mstest runner.

When running the test in debug mode using ncrunch, the test completes (ie: the test method executes and the test clean up code all runs and only after that does the error occur) - now, I'm spawning threads specifically around using await/async but also using manualresetevents to wait for events to be fired before verifying. (These are all verifying as expected but just trying to provide as much information as possible).

In normal mode, the application failure details are (that's from windows debug)

Problem signature:
Problem Event Name: APPCRASH
Application Name: nCrunch.TestHost.x86.exe
Application Version: 0.0.0.0
Application Timestamp: 515a000a
Fault Module Name: nCrunch.TestHost.x86.exe
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 515a000a
Exception Code: 40000015
Exception Offset: 0000160d
OS Version: 6.1.7601.2.1.0.256.4
Locale ID: 2057
Additional Information 1: 515d
Additional Information 2: 515de2a7e202eb6e447976e7367e1cd5
Additional Information 3: 01b1
Additional Information 4: 01b1f0b9ec860427398cdf1c0e1c633a

s0127786
#4 Posted : Friday, June 7, 2013 11:38:14 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/7/2013(UTC)
Posts: 3

Ok, just to update this - by not closing the tcp client contained on the tcp server (ie: the client that the server accepted) then the problem disappears.
Remco
#5 Posted : Friday, June 7, 2013 11:58:08 AM(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)
Thanks this gives us some good information to work with. I think this issue is being caused by the code under test overstepping the test boundaries with multithreading. I haven't seen a multithreading issue take down an entire process before, but there is a very broad range of problems that can happen if code is still being executed after the test has completed. The .NET TCP components are themselves built over unmanaged code, so it's possible that something is bombing out on cleanup in a really messy way.

The use case you're testing for (i.e. client/server connections) is notoriously difficult to isolate with good tests, because the connection handling between client and server generally has many race conditions that can be hard to pin down. Make sure the connections are being closed in a carefully determined sequence and that all events have finished firing by the time the test completes. It may be necessary to add a Thread.Sleep at the end of the test. You might find it's possible that other test runners won't show this problem because they generally tear down the test process immediately on completion of execution (where NCrunch will keep it alive for as long as is resource-efficient).
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.050 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download