-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Wait-Process: add -Any and -PassThru parameters #19423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
321e5cc
Wait-Process: add `-Any` parameter
dwtaber f48f1f6
Wait-Process: add `-PassThru` parameter
dwtaber a3c2371
Wait-Process: use `Any` instead of `_any` in ifs
dwtaber b01e771
Remove inadvertent extra whitespace
dwtaber 5072e0c
Merge branch 'PowerShell:master' into wait-process-any
dwtaber 0fb665d
Rewrite new parameters as auto-properties
dwtaber 455436a
Simplify conditional on myProcess_Exited
dwtaber 8a059c0
Update new parameters' summaries per CodeFactor
dwtaber 1331415
Reorder conditions in myProcess_Exited
dwtaber 6060a92
remove _initialNumberOfProcesses, add hasTimedOut
dwtaber 1a33f66
Update src/Microsoft.PowerShell.Commands.Management/commands/manageme…
dwtaber 3c74053
Merge branch 'PowerShell:master' into wait-process-any
dwtaber 7147bf8
Add tests for Wait-Process
dwtaber a6f66b7
Process.cs: add OutputType; named argument
dwtaber 47b3709
Reduced whitespace before Should in tests
dwtaber 21cc089
Update test/powershell/Modules/Microsoft.PowerShell.Management/Wait-P…
dwtaber 9ba8e30
Add fixes/tests for processes that end before wait
dwtaber 3709806
Merge branch 'PowerShell:master' into wait-process-any
dwtaber 97ee03f
Remove blank line before `else if`
dwtaber 69219f1
Remove WindowStyle details from tests.
dwtaber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
74 changes: 74 additions & 0 deletions
74
test/powershell/Modules/Microsoft.PowerShell.Management/Wait-Process.Tests.ps1
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| Describe "Wait-Process" { | ||
|
|
||
| BeforeAll { | ||
| $pingCommandPath = (Get-Command -CommandType Application ping)[0].Definition | ||
|
|
||
| $startProcessArgs = @{ | ||
| FilePath = $pingCommandPath | ||
| PassThru = $true | ||
| } | ||
| $nc = $IsWindows ? "-n" : "-c" | ||
|
|
||
| function longPing { Start-Process @startProcessArgs -ArgumentList "$nc 10 localhost" } | ||
| function shortPing { Start-Process @startProcessArgs -ArgumentList "$nc 2 localhost" } | ||
SteveL-MSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| BeforeEach { | ||
| $Processes = @( 1..3 | ForEach-Object { longPing } ) + ($shortPing = shortPing) | ||
| } | ||
|
|
||
| AfterEach { | ||
| Stop-Process -InputObject $Processes | ||
| } | ||
|
|
||
| It "Should wait until all processes have exited" { | ||
| Wait-Process -InputObject $Processes | ||
|
|
||
| $Processes.Where({$_.HasExited -eq $true}).Count | Should -Be $Processes.Count | ||
| } | ||
|
|
||
| It "Should return after all processes have exited, even if some exit before the wait starts." { | ||
| Wait-UntilTrue -sb { $shortPing.HasExited -eq $true } -IntervalInMilliseconds 100 | ||
| Wait-Process -InputObject $Processes | ||
|
|
||
| $Processes.Where({$_.HasExited -eq $true}).Count | Should -Be $Processes.Count | ||
| } | ||
|
|
||
| It "Should return immediately if all processes have exited before the wait starts" { | ||
| Wait-UntilTrue -sb { $Processes.HasExited -NotContains $false } -IntervalInMilliseconds 100 | ||
| Wait-Process -InputObject $Processes | ||
|
|
||
| $Processes.Where({$_.HasExited -eq $true}).Count | Should -Be $Processes.Count | ||
| } | ||
|
|
||
| It "Should return immediately if at least one process has exited before the wait starts" { | ||
| Wait-UntilTrue -sb { $shortPing.HasExited -eq $true } -IntervalInMilliseconds 100 | ||
| Wait-Process -InputObject $Processes -Any | ||
|
|
||
| $Processes.Where({$_.HasExited -eq $true}).Count | Should -Be 1 | ||
| $Processes.Where({$_.HasExited -eq $false}).Count | Should -Be ($Processes.Count - 1) | ||
| } | ||
|
|
||
| It "Should wait until any one process has exited" { | ||
| Wait-Process -InputObject $Processes -Any | ||
|
|
||
| $Processes.Where({$_.HasExited -eq $true}).Count | Should -Be 1 | ||
| $Processes.Where({$_.HasExited -eq $false}).Count | Should -Be ($Processes.Count - 1) | ||
| } | ||
|
|
||
| It "Should passthru all processes when all processes have exited" { | ||
| $PassThruProcesses = Wait-Process -InputObject $Processes -PassThru | ||
|
|
||
| $PassThruProcesses.Where({$_.HasExited -eq $true}).Count | Should -Be $Processes.Count | ||
| } | ||
|
|
||
| It "Should passthru all processes when any one process has exited" { | ||
| $PassThruProcesses = Wait-Process -InputObject $Processes -Any -PassThru | ||
|
|
||
| $PassThruProcesses.Where({$_.HasExited -eq $true}).Count | Should -Be 1 | ||
| $PassThruProcesses.Where({$_.HasExited -eq $false}).Count | Should -Be ($Processes.Count - 1) | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.