Skip to content
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

Bug: Excluded method is still included in the coverage report #1389

Closed
extesy opened this issue Oct 7, 2022 · 12 comments
Closed

Bug: Excluded method is still included in the coverage report #1389

extesy opened this issue Oct 7, 2022 · 12 comments
Labels
needs repro Needs repro to be investigated, cannot repro in local stale

Comments

@extesy
Copy link

extesy commented Oct 7, 2022

I think there is a regression from #849 bug fix. We are using coverlet 3.1.2 running on .net 6. There is a method declared like this:

    [ExcludeFromCodeCoverage]
    internal virtual async Task<RedisValue[]> DoRedisExecuteAsync(IRedisClient redisClient, string scriptContents, RedisKey redisKey, long exclusiveUpperBound)
    {
        var result = await redisClient.ExecuteAsync(async database =>
            await database.ScriptEvaluateAsync(scriptContents, keys: new[] { redisKey }, values: new RedisValue[] { exclusiveUpperBound })!
        )!;
        return (RedisValue[])result;
    }

When running unit tests and collecting coverage report, this method is still included in the report. Here is the relevant portion of the coverage report in different formats:

        <class name="CollectiblesItemService.SerialExecutor.DataLayer.RedisSerialCounterRepository/&lt;&gt;c__DisplayClass10_0/&lt;&lt;DoRedisExecuteAsync&gt;b__0&gt;d" filename="services/collectibles-item-service/src/SerialExecutor/DataLayer/SerialCounter/RedisSerialCounterRepository.cs" line-rate="0" branch-rate="1" complexity="1">
          <methods>
            <method name="MoveNext" signature="()" line-rate="0" branch-rate="1" complexity="1">
              <lines>
                <line number="167" hits="0" branch="False" />
              </lines>
            </method>
          </methods>
          <lines>
            <line number="167" hits="0" branch="False" />
          </lines>
        </class>
FN:166,System.Void CollectiblesItemService.SerialExecutor.DataLayer.RedisSerialCounterRepository/<>c__DisplayClass10_0/<<DoRedisExecuteAsync>b__0>d::MoveNext()
FNDA:0,System.Void CollectiblesItemService.SerialExecutor.DataLayer.RedisSerialCounterRepository/<>c__DisplayClass10_0/<<DoRedisExecuteAsync>b__0>d::MoveNext()
DA:167,0

Line 167 is the await database.ScriptEvaluateAsync line from that method. Somehow that single line is declared as "not covered" instead of being excluded with the rest of the method.

It might have something to do with this line being async lambda which complies into a more complicated state machine.

@daveMueller daveMueller added the untriaged To be investigated label Oct 7, 2022
@daveMueller
Copy link
Collaborator

Thanks for reporting this.

@extesy
Copy link
Author

extesy commented Oct 10, 2022

Found a relevant stackoverflow: https://stackoverflow.com/questions/72487078/c-sharp-exclude-lambda-expression-from-code-coverage/72487708#72487708. Seems like coverlet is unable to trace the lambda function back to the function that contains it.

@daveMueller
Copy link
Collaborator

You are right it seems so. I thought we have an algorithem for that but I also could be wrong. At least those two issues somehow seem to be related. #1302, #129.

@daveMueller daveMueller added the waiting for customer Waiting for customer action label Nov 27, 2022
@extesy
Copy link
Author

extesy commented Nov 27, 2022

@daveMueller What does waiting for customer label mean? Do you need me to provide some extra information?

@daveMueller
Copy link
Collaborator

Ohh sorry for that. I most likely fell asleep before I could hit the comment button yesterday 🙈 . I tried to reproduce this yesterday but wasn't able to.

grafik

Could you try to create a simple repro for that issue?

@daveMueller
Copy link
Collaborator

I now also tried the code from the stackoverflow issue you referenced. But I'm also not able to reproduce this.

grafik

@daveMueller daveMueller added needs repro Needs repro to be investigated, cannot repro in local and removed untriaged To be investigated labels Nov 27, 2022
@Nodnarb3
Copy link

Nodnarb3 commented Nov 29, 2022

Seeing the same issue on Coverlet 3.1.0 on .NET 6

image

Haven't tried updating, so could this be something that has since been patched in 3.2.0 maybe?

@daveMueller
Copy link
Collaborator

@Nodnarb3 I don't really think so. At least I can't remember a bugfix for an issue like that in the last release. Could you tell me how you build the assemblies under test? Do you maybe have a release build configuration?

@Nodnarb3
Copy link

Nodnarb3 commented Dec 5, 2022

Projects are being built as follows, with BuildConfiguration set to debug:

...
  # Build all projects and don't allow warnings
  - task: DotNetCoreCLI@2
    displayName: 'dotnet build'
    inputs:
      command: build
      projects: '**/*.csproj'
      arguments: '/warnaserror --configuration $(BuildConfiguration)'

  # Test all projects and collect coverage results
  - task: DotNetCoreCLI@2
    displayName: 'dotnet test'
    inputs:
      command: 'test'
      projects: '${{ parameters.testGlob }}'
      arguments: '--configuration $(BuildConfiguration) --settings ./server/coverlet.runsettings --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura'
...

coverlet.runsettings:

<?xml version="1.0" encoding="utf-8"?>
<!-- File name extension must be .runsettings -->
<RunSettings>
	<DataCollectionRunSettings>
		<DataCollectors>
			<DataCollector friendlyName="XPlat Code Coverage">
				<Configuration>
                    <ExcludeByFile>**/Migrations/*.cs</ExcludeByFile>
                    <SingleHit>True</SingleHit>
				</Configuration>
			</DataCollector>
		</DataCollectors>
	</DataCollectionRunSettings>
</RunSettings>

@daveMueller
Copy link
Collaborator

Thanks @Nodnarb3, nothing really out of the ordinary. Unfortunately I still can't reproduce it.
We would really appreciate if someone who has this issue could try to provide a simple repro.
But don't feel obligated this is still open source.

@daveMueller daveMueller removed the waiting for customer Waiting for customer action label Dec 6, 2022
@github-actions
Copy link

github-actions bot commented Sep 3, 2023

This issue is stale because it has been open for 3 months with no activity.

@github-actions github-actions bot added the stale label Sep 3, 2023
Copy link

github-actions bot commented Jun 9, 2024

This issue was closed because it has been inactive for 9 months since being marked as stale.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Needs repro to be investigated, cannot repro in local stale
Projects
None yet
Development

No branches or pull requests

3 participants