microsoft / microsoft/codecoverage

dotnet-coverage collect --server-mode leaks coverage across tests when using snapshot -r

Offen
#246 6 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
C#
Sterne
125
Forks
17
Ø Merge
1 Std. 17 Min.
Gemergte PRs (30 T.)
2

Beschreibung

We are observing that in a long-lived server-mode session, calling snapshot -r does not appear to fully clear prior coverage state. Coverage from an earlier test is still present in the next snapshot, and the raw .coverage file is already corrupted before any mapper/parsing logic executes. This is causing to collect the per test coverage when the test cases needs to run in sequence.

Steps:

  1. Start a shared coverage session:
    cmd : dotnet-coverage collect --server-mode --background --session-id
    2. Connect and run Test A in that same session:
    cmd : dotnet-coverage connect dotnet test
    3. Snapshot Test A with reset:
    cmd : dotnet-coverage snapshot -r -o -t
    dotnet-coverage merge -o -f xml
    4. Connect and run Test B in the same session:
    cmd : dotnet-coverage connect dotnet test
    5. Snapshot Test B with reset:
    cmd : dotnet-coverage snapshot -r -o -t
    dotnet-coverage merge -o -f xml
    6. Observe coverage contamination between Test A and Test B.
    7. Shut down the server at the end
    cmd: dotnet-coverage shutdown -t

Expected:
Each snapshot should produce coverage for only the test that executed since the previous reset. The -r option should clear the previous coverage state after creating the snapshot.

Actual:
The second snapshot still contains coverage from the earlier test or from a previous unrelated run. The raw .coverage output is already incorrect before mapper logic runs, which indicates the issue is in the coverage engine/server-mode reset behavior and not in downstream parsing.

Impact:
Incorrect coverage attribution, false pass/fail evidence, broken file-to-test mapping.

Note:
This issue is specific to dotnet-coverage collect --server-mode with repeated snapshot -r calls in the same process/session. It is not the same as MTP JSON-RPC server mode (--server / --server jsonrpc), which is a separate feature for IDE/tooling integration. The bug is therefore in the coverage collector/server-mode flow, not in the MTP test runner or mapper logic.

Relevant docs:

https://learn.microsoft.com/en-us/dotnet/core/testing/microsoft-testing-platform-code-coverage
https://learn.microsoft.com/en-us/dotnet/core/testing/microsoft-testing-platform-server-mode
https://github.com/microsoft/codecoverage

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem dokumentierten server-mode-Ablauf und reproduziere das Problem mit den aufgelisteten Befehlen collect, connect, snapshot -r, merge und shutdown für Test A und Test B. Untersuche die rohen Snapshot-Ausgaben vor der Merge- oder Mapper-Verarbeitung; abgeschlossen ist die Aufgabe, wenn jeder Snapshot nur die seit dem vorherigen Reset erfasste Coverage enthält, ohne die .coverage-Datei zu beschädigen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp
Bereich
testing, tooling
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Aktiv
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
52/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.