Collect code coverage in parallel runs#2860
Open
nohwnd wants to merge 1 commit into
Open
Conversation
Run.Parallel previously fell back to sequential (with a warning) whenever CodeCoverage was enabled. Enable coverage in parallel instead: each worker measures its file with breakpoints (the default profiler/tracer keeps state in a process-global static and is not concurrency-safe across runspaces) and returns its per-location hits. The parent merges every worker's hits, adds the coverage of any #pester:no-parallel files it runs in-session, and lets the Coverage plugin's End step emit the single merged report and output file. PowerShell 5.1 remains unsupported for parallel and still falls back to a sequential run (collecting coverage sequentially) with the version warning. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Run.Parallelpreviously fell back to a sequential run (with a warning) wheneverCodeCoveragewas enabled. This enables coverage collection during parallel runs instead.#pester:no-parallelfiles it runs in-session, and lets the existing Coverage pluginEndstep emit the single merged report and output file (JaCoCo/Cobertura) plusrun.CodeCoverage.ForEach-Object -Parallel.Changes
src/functions/Pester.Parallel.ps1— workers enable breakpoint coverage, suppress their own report/file write via aCodeCoverageSkipReportmodule flag, and return a lightweight per-location hit projection.src/functions/Coverage.ps1— newMerge-CoverageFromParallelandConvert-CommandCoverageToProjectionhelpers.src/functions/Coverage.Plugin.ps1—Endstep honors the skip flag and readsUseBreakpointsfrom the captured plugin configuration.src/Main.ps1— removes the coverage fallback/warning; collects worker coverage, measures#pester:no-parallelfiles in-session, merges everything, and hands it to the Coverage plugin for the single report.tst/Pester.RSpec.Parallel.ts.ps1— replaces the obsolete "falls back with warning when CodeCoverage" test with two tests: parallel coverage equals sequential, and coverage from a#pester:no-parallelfile is merged in.Verification
#pester:no-parallelcase merges correctly; JaCoCo + Cobertura XML valid; output file written; no stray worker output files.Related to #1704.