coverlet icon indicating copy to clipboard operation
coverlet copied to clipboard

Incorrect branch coverage with await context.SaveChangesAsync()

Open mu88 opened this issue 2 years ago • 1 comments

I have the following code:

await using DbContext context = await ContextFactory.CreateDbContextAsync();
await context.SaveChangesAsync();

Giving me this branch coverage:
image

This is the IL for await context.SaveChangesAsync();:

// [43 9 - 43 66]
IL_00b3: ldarg.0      // this
IL_00b4: ldfld        class MyCompany.MyApplication.Core.Persistence.DbContext valuetype MyCompany.MyApplication.Core.Persistence.Repositories.BaseRepository`2/'<DoSomethingAsync>d__10'<!0/*TEntity*/, !1/*TContract*/>::'<context>5__2'
IL_00b9: ldarg.0      // this
IL_00ba: ldfld        string valuetype MyCompany.MyApplication.Core.Persistence.Repositories.BaseRepository`2/'<DoSomethingAsync>d__10'<!0/*TEntity*/, !1/*TContract*/>::key
IL_00bf: call         class [System.Runtime]System.Threading.Tasks.Task`1<!0/*TEntity*/> class MyCompany.MyApplication.Core.Persistence.Repositories.BaseRepository`2<!0/*TEntity*/, !1/*TContract*/>::FirstOrDefaultAsync(class MyCompany.MyApplication.Core.Persistence.DbContext, string)
IL_00c4: callvirt     instance valuetype [System.Runtime]System.Runtime.CompilerServices.TaskAwaiter`1<!0/*TEntity*/> class [System.Runtime]System.Threading.Tasks.Task`1<!0/*TEntity*/>::GetAwaiter()
IL_00c9: stloc.s      V_6

mu88 avatar Feb 16 '23 14:02 mu88

Source code is here: https://github.com/GodelTech/GodelTech.Messaging.AzureServiceBus Changes: https://github.com/GodelTech/GodelTech.Messaging.AzureServiceBus/pull/13 SonarCloud: https://sonarcloud.io/component_measures?metric=new_coverage&selected=GodelTech_GodelTech.Messaging.AzureServiceBus%3Asrc%2FGodelTech.Messaging.AzureServiceBus%2FAzureServiceBusSender.cs&view=list&pullRequest=13&id=GodelTech_GodelTech.Messaging.AzureServiceBus

rodchenkov avatar Feb 16 '23 14:02 rodchenkov

@rodchenkov thanks a lot for the repro. We already fixed this with PR #1647. Your repro helped me now to confirm that it's already fixed in our nightly build. A description on how to consume our nightly can be found here.

coverlet v6.0.2

grafik

coverlet nightly

grafik

Feel free to reopen.

daveMueller avatar Aug 07 '24 21:08 daveMueller