question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Coverage Issue - New Using + Async/Await + ConfigureAwait

See original GitHub issue

found during #649, this combination of code seems to have incorrect reports

        public async Task<ActionResult<IEnumerable<SystemUserItem>>> SystemUsers(CancellationToken ct)
        {
            using var data = this.factory.CreateReadOnly<SystemUserItem>();

            var list = await data.AllAsync(ct)
                .ConfigureAwait(false);

            return this.Ok(list);
        }

here is the final report output:

image

here is the diff of the coverage xml: image

left side = unit test - code is not executed right side = integration test - code is there doesnt appear to be any branches - all code execute under a single call

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:21

github_iconTop GitHub Comments

3reactions
MarcoRossignolicommented, Jan 21, 2020

Guys I found the issue…I’PR a fix asap. Are two different issue, one related to netstandard project and the other related on new async machine state code.

1reaction
MarcusOttercommented, Jan 29, 2020

Adding a script that moves the files was a good call, I got it working and the problems with new using and async/await with ConfigureAwait disappeared 😃

For future reference if anyone encounters the problem, take a look at the relevant files below.

build.yml (GitHub Workflow)

- name: Install coverlet
  run: dotnet add src/ApodTests/ApodTests.csproj package coverlet.collector --version 1.2.25-g074a201a91 --source https://www.myget.org/F/coverlet-dev/api/v3/index.json

- name: Run tests
  run: dotnet test src/ApodTests/ApodTests.csproj --collect:"XPlat Code Coverage" --settings ./src/ApodTests/.runsettings

- name: Move test coverage results UNIX
  if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
  run: mv src/ApodTests/coverage/**/*.info .

- name: Move test coverage results WINDOWS
  if: matrix.os == 'windows-latest'
  run: move src\ApodTests\coverage\**\*.info .

- name: Coveralls GitHub Action
  uses: coverallsapp/github-action@v1.0.1
  with: 
    github-token: ${{ secrets.GITHUB_TOKEN }}
    path-to-lcov: coverage.info

ApodTests.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
    <PackageReference Include="Moq" Version="4.13.1" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="1.2.25-g074a201a91">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Apod\Apod.csproj" />
  </ItemGroup>

</Project>

.runsettings in the root test folder (with ApodTests.csproj)

<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
  <RunConfiguration>
    <ResultsDirectory>coverage</ResultsDirectory>
  </RunConfiguration>
  <DataCollectionRunSettings>
    <DataCollectors>
      <DataCollector friendlyName="XPlat code coverage">
        <Configuration>
          <Format>lcov</Format>
        </Configuration>
      </DataCollector>
    </DataCollectors>
  </DataCollectionRunSettings>
</RunSettings>

And finally, the NuGet.Config in the root solution folder

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <!-- Coverlet nightly build feed -->
    <add key="coverletNightly" value="https://www.myget.org/F/coverlet-dev/api/v3/index.json" /> 
    <!-- Default nuget feed -->
    <add key="nuget" value="https://api.nuget.org/v3/index.json" /> 
    <!-- Add all other needed feed -->
  </packageSources>
</configuration>

I’m back to 100% 😃 Thank you for the help @MarcoRossignoli!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Coverage Issue - New Using + Async/Await + ConfigureAwait
Guys I found the issue...I'PR a fix asap. Are two different issue, one related to netstandard project and the other related on new...
Read more >
c# - Why is writing ConfigureAwait(false) on every line with ...
As a general rule, yes. ConfigureAwait(false) should be used for every await unless the method needs its context.
Read more >
Why I no longer use ConfigureAwait(false)
In this case, I believe that using ConfigureAwait(false) for the ... var tcs = new TaskCompletionSource(); var task = SomeAsync(() => tcs.
Read more >
Async, Await, and ConfigureAwait – Oh My!
ConfigureAwait (false) on every async call through the entire call stack! If you don't, you'll end up with another deadlock. The problem here...
Read more >
When to use ConfigureAwait(false)? : r/csharp
No, it means “do await, but don't continue on the context”. I could've sworn there was an issue about improving this API, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found