Skip to content

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

@extesy

Description

@extesy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs reproNeeds repro to be investigated, cannot repro in localstale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions