microsoft / microsoft/codecoverage
dotnet-coverage collect --server-mode leaks coverage across tests when using snapshot -r
Nessuno ha ancora preso questa issue.
- Lingua principale
- C#
- Stelle
- 125
- Fork
- 17
- Merge medio
- 1h 17m
- PR unite (30g)
- 2
Descrizione
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:
- 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
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con il flusso documentato di server-mode e riproduci il problema usando i comandi elencati collect, connect, snapshot -r, merge e shutdown per Test A e Test B. Esamina gli output grezzi degli snapshot prima dell'elaborazione da parte di merge o mapper; il lavoro è completato quando ogni snapshot contiene solo la coverage raccolta dal reset precedente, senza corrompere il file .coverage.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp
- Ambito
- testing, tooling
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Attiva
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 52/100