-
Notifications
You must be signed in to change notification settings - Fork 388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Branch coverage with async calls #113
Comments
I've noticed the same thing. My hunch (totally a guess here, so take it for what it's worth) is that the branch inserted by the compiler for awaiting code (such that you don't actually wait if the task has already completed) is being interpreted as a branch in your code. If this is true, I don't think it's a meaningful distinction in 99+% of code. There are only two cases where I can think of that this matters. The first is using |
We've noticed the same thing, and I put together a repro where |
Thanks for reporting this guys. I'm currently working on general improvements to the coverage logic so will add this to the list. Thanks for the test project @abe545 |
+1 |
I'm seeing this issue still in version 2.5.1 (that's the version number in Nuget). |
@sugarjig can you provide a repro? |
Same with 2.6.0 |
@soljarka can you provide a repro? |
I don't know if this is old news, but I think I figured out a way through. By adding a simple continuation I was able to get Coverlet to consider all branches hit. For example:
I hope that helps others. |
Thanks @Rjae for the comment...can you provide a repro of the issue (I mean a piece of code without continuation that leads to invalid async branch coverage)? |
Sure thing bro...literally the same line without the ContinueWith. So...
I've used same approach in several more lines with same success. |
Thanks I'll take a look asap |
Wow...thanks! Additional "discovery": ContinueWith does not appear to solve the coverage reporting for |
BTW, I'm looking for a temporary ignore for these cases. I've tried following attribute-excludes: |
@Rjae add |
@MarcoRossignoli again, thanks! Will watch for async fix. |
Seeing this in the latest coverlet (3.1.2). Using Cake.Coverlet 2.5.4. Happens with all the HttpClient async requests I'm using
|
Another workaround I found is to change |
Hi @brad, thanks for the report. Can you create a new issue on it, to make it possible to track? If you have a small example reproducing the issue it's really useful too. |
@brad note - your suggestion also changes the functionality of the code with regards to asynchrony. Depending on the performance requirements of your code, it may be a really bad tradeoff to work around a coverage issue. |
@nycdotnet Thanks for the heads up @petli Sure, no problem |
@petli Is there a forum/chat group to get support? I'm testing this with a minimal application and am not able to reproduce the issue there so clearly I am doing something wrong |
@brad There's a discussion forum here: https://github.com/coverlet-coverage/coverlet/discussions |
I have a project using EF Core with async methods that shows a branch at each await call. One of the branches always shows as uncovered. I've created a sample repo that repoduces the problem here. You can see the branch in the coverage report but the referenced line does not have a branch.
Here is the output of
dotnet test
:I tired another example with
await HttpClient.GetAsync(...)
but that did not seem to produce the same issue so this doesn't appear to apply to all awaited calls.The text was updated successfully, but these errors were encountered: