Replay parallel worker debug output interleaved with tests#2854
Draft
nohwnd wants to merge 1 commit into
Draft
Conversation
Debug output (Debug.WriteDebugMessages, enabled e.g. by Output.Verbosity = 'Diagnostic') was written straight to the host by each parallel worker as it ran, so it appeared up front, detached from the test that produced it. Capture host/debug output into the same event tape the recorder already uses and replay it in tape order from the parent. Each worker runs one file synchronously, so append order is the correct order and the debug lines land interleaved with the per-test output they belong to. - Output.ps1: Write-PesterHostMessage appends to the worker's tape (script-scoped parallelOutputTape) instead of writing live. - Pester.Parallel.ps1: point the tape at the recorder's list and split the tape positionally at ContainerDiscoveryEnd so host entries stay in the phase they were produced in. - Main.ps1: replay host entries (Step = $null) to the real host and drop the warning this branch previously added. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
aa07224 to
42ad920
Compare
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.
Fix #2825
Problem
When running with
Run.Parallel = $trueandOutput.Verbosity = 'Diagnostic'(orDebug.WriteDebugMessagesotherwise enabled), diagnostic output such asMockdebug messages was printed before the test results and detached from the test that produced it, so it was impossible to associate the output with a specific test.Why it happened
In a parallel run each file executes in its own worker runspace. The worker runs silently (
Output.Verbosity = 'None') and records the plugin events onto a tape that the parent replays in test order to produce console output. Debug output, however, went throughWrite-PesterHostMessageand was written straight to the host as the worker executed — it was never part of the replayed tape. So every worker's debug lines surfaced up front, out of order relative to the per-test output.Fix
Capture the worker's host/debug output into the same event tape the recorder already uses, and replay it from the parent in tape order. Because each worker runs a single file synchronously, append order is already the correct order, so the debug lines come back interleaved with the per-test output they belong to instead of dumped up front.
Output.ps1— when a worker'sparallelOutputTapeis set,Write-PesterHostMessageappends the message to the tape (aStep = $nullentry carrying the bound parameters) instead of writing to the host live.Pester.Parallel.ps1— point the tape at the recorder's list so plugin steps and host/debug output share one ordered tape, and split the tape positionally atContainerDiscoveryEndso each host entry stays in the phase (discovery vs. run) it was produced in.Main.ps1— the parent replays host entries (Step = $null) to the real host in position; the earlier warning about uncorrelated debug output is removed since the output is now correlated.Tests
Replaced the two tests in
tst/Pester.RSpec.Parallel.ts.ps1: one runs two files in parallel withDiagnosticoutput and asserts the debug output is captured and replayed interleaved with each file's tests (on PS7+ it also checks the second file's discovery output lands after the first file's result); the other asserts the run no longer warns about uncorrelated debug output. The full parallel suite (21 tests) andOutput.Tests.ps1(55 tests) pass, and the custom build analyzer reports no new findings in the changed files.