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

Notification

Icon
Error

Coverage markers indicate 0ms for await/async tests in NUnit
GreenMoose
#1 Posted : Wednesday, October 19, 2016 9:50:12 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 507

Thanks: 145 times
Was thanked: 66 time(s) in 64 post(s)
[v2.24.0.2]

When I run async Test in NUnit the coverage markers indicate "0ms" on the awaited method. Is this a bug or "by design" ?

See http://screencast.com/t/1mwMqiK0bi
Code:

        [TestFixture]
        internal class TestFixture
        {
            private async Task FooAsync()
            {
                await Task.Delay(1000);
            }
            [Test]
            public async Task AsyncTest()
            {
                await FooAsync();
            }
            [Test]
            public void NonAsyncTest()
            {
                FooAsync().Wait();
            }
            
        }


Thanks.
Remco
#2 Posted : Wednesday, October 19, 2016 10:03:23 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,161

Thanks: 964 times
Was thanked: 1296 time(s) in 1202 post(s)
Hi, thanks for posting!

This is by design. It is due to the mechanics through which the await construction is implemented.

When the .NET runtime hits the await, it actually runs the thread through to completion and sets up a continuation pointed back at the await. When the awaited call completes, a new thread picks up the code from the point where the calling method was interrupted.

These mechanics happen above the level at which NCrunch operates, so the coverage tracking is completely unaware of them.

'await' was implemented by Microsoft in the same manner as 'yield'; all the complexity is in the compiler rather than in the runtime. This means that if you look at the MSIL generated from class using await, you'll see an extensive set of compiler generated methods and classes that have little to do with your own code and much more to do with the piping around await itself. It is theoretically possible for NCrunch to be upgraded to identify the 'await' by closely inspecting and analysing this structure, but this will come at a serious cost in terms of lost performance and significant complexity - it likely wouldn't be worth it.
GreenMoose
#3 Posted : Thursday, October 20, 2016 9:22:49 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 507

Thanks: 145 times
Was thanked: 66 time(s) in 64 post(s)
Thanks for the reply.

I understand the complexity of supporting this but IMHO the hotspot indicators in NCrunch is one of those "killer features" that stands out. Given that asynchronous programming is getting more mainstream (even Entity Framework supports it :)) maybe this is a feature request that will raise in popularity with time.

But future will tell I guess :).
Remco
#4 Posted : Thursday, October 20, 2016 11:09:12 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,161

Thanks: 964 times
Was thanked: 1296 time(s) in 1202 post(s)
GreenMoose;9328 wrote:
Thanks for the reply.

I understand the complexity of supporting this but IMHO the hotspot indicators in NCrunch is one of those "killer features" that stands out. Given that asynchronous programming is getting more mainstream (even Entity Framework supports it :)) maybe this is a feature request that will raise in popularity with time.

But future will tell I guess :).


Fair enough :) If you'd like to drop it on uservoice as a feature request, it may become popular enough to be worth investigating more.
GreenMoose
#5 Posted : Thursday, October 20, 2016 11:35:39 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 507

Thanks: 145 times
Was thanked: 66 time(s) in 64 post(s)
1 user thanked GreenMoose for this useful post.
Remco on 10/20/2016(UTC)
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.032 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download