-
Notifications
You must be signed in to change notification settings - Fork 315
/
test_supervisor_restarts.ps1
71 lines (59 loc) · 2.79 KB
/
test_supervisor_restarts.ps1
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
# A simple test that the launcher restarts a supervisor when it exits abruptly
# The one optional argument set the exit code of the supervisor (default: 1).
# By default this runs against the installed habitat binaries. To override and
# test locally-built code, set overrides in the environment of the script.
# See https://github.com/habitat-sh/habitat/blob/master/BUILDING.md#testing-changes
Describe "Supervisor restarts on abrupt exit" {
$exit_file = New-TemporaryFile
$env:HAB_FEAT_TEST_EXIT = $exit_file
$supLog = New-SupervisorLogFile("supervisor_restarts_on_abrupt_exit")
$launcher_proc = Start-Supervisor -Timeout 45 -LogFile $supLog
$supervisor_proc = Get-Process hab-sup
Set-Content $exit_file -Value 1
$testScript = { $supervisor_proc.HasExited }
$timeoutScript = { Write-Error "Timed out waiting for Supervisor to exit" }
Wait-True -TestScript $testScript -TimeoutScript $timeoutScript -Timeout 45
$testScript = { Get-Process hab-sup -ErrorAction SilentlyContinue }
$timeoutScript = { Write-Error "Timed out waiting for Supervisor to be restarted" }
Wait-True -TestScript $testScript -TimeoutScript $timeoutScript -Timeout 45
$new_supervisor_proc = Get-Process hab-sup
$new_launcher_proc = Get-Process hab-launch
It "will not exit the launcher" {
$launcher_proc.HasExited | Should -Be $false
}
It "will spawn a new supervisor" {
$new_supervisor_proc.Id | Should -Not -Be $supervisor_proc.Id
}
It "will not spawn a new launcher" {
$new_launcher_proc.Id | Should -Be $launcher_proc.Id
}
AfterAll {
Stop-Supervisor
}
}
Describe "Supervisor restarts on 'hab sup restart'" {
$supLog = New-SupervisorLogFile("supervisor_restarts_on_hab_sup_restart")
$launcher_proc = Start-Supervisor -Timeout 45 -LogFile $supLog
$supervisor_proc = Get-Process hab-sup
Invoke-NativeCommand hab sup restart
$testScript = { $supervisor_proc.HasExited }
$timeoutScript = { Write-Error "Timed out waiting for Supervisor to exit" }
Wait-True -TestScript $testScript -TimeoutScript $timeoutScript -Timeout 45
$testScript = { Get-Process hab-sup -ErrorAction SilentlyContinue }
$timeoutScript = { Write-Error "Timed out waiting for Supervisor to be restarted" }
Wait-True -TestScript $testScript -TimeoutScript $timeoutScript -Timeout 45
$new_supervisor_proc = Get-Process hab-sup
$new_launcher_proc = Get-Process hab-launch
It "will not exit the launcher" {
$launcher_proc.HasExited | Should -Be $false
}
It "will spawn a new supervisor" {
$new_supervisor_proc.Id | Should -Not -Be $supervisor_proc.Id
}
It "will not spawn a new launcher" {
$new_launcher_proc.Id | Should -Be $launcher_proc.Id
}
AfterAll {
Stop-Supervisor
}
}