forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWait-Process.Tests.ps1
More file actions
74 lines (54 loc) · 2.82 KB
/
Copy pathWait-Process.Tests.ps1
File metadata and controls
74 lines (54 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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" }
}
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)
}
}