@@ -52,6 +52,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
52
52
# Drop created objects
53
53
$conn.ExecuteNonQuery (" IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name = 'dbatoolsci_session_invalid') DROP EVENT SESSION [dbatoolsci_session_invalid] ON SERVER;" )
54
54
$conn.ExecuteNonQuery (" IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name = 'dbatoolsci_session_valid') DROP EVENT SESSION [dbatoolsci_session_valid] ON SERVER;" )
55
+ Get-DbaAgentSchedule - SqlInstance $script :instance2 - Schedule " XE Session START - dbatoolsci_session_valid" , " XE Session STOP - dbatoolsci_session_valid" | Remove-DbaAgentSchedule - Force - Confirm:$false
55
56
}
56
57
57
58
Context " Verifying command works" {
@@ -90,22 +91,34 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
90
91
It " works when -StopAt is passed" {
91
92
$StopAt = (Get-Date ).AddSeconds(10 )
92
93
Start-DbaXESession $server - Session $dbatoolsciValid.Name - StopAt $StopAt - WarningAction SilentlyContinue
94
+ $dbatoolsciValid.Refresh ()
93
95
$dbatoolsciValid.IsRunning | Should Be $true
94
96
(Get-DbaAgentJob - SqlInstance $server - Job " XE Session STOP - dbatoolsci_session_valid" ).Count | Should - Be 1
95
97
$stopSchedule = Get-DbaAgentSchedule - SqlInstance $server - Schedule " XE Session STOP - dbatoolsci_session_valid"
96
98
$stopSchedule.ActiveStartTimeOfDay.ToString (' hhmmss' ) | Should - Be $StopAt.TimeOfDay.ToString (' hhmmss' )
97
99
$stopSchedule.ActiveStartDate | Should - Be $StopAt.Date
100
+ Start-Sleep - Seconds 11
101
+ $dbatoolsciValid.Refresh ()
102
+ $dbatoolsciValid.IsRunning | Should Be $false
103
+ # Using $script:instance2 because the SMO $server is not updated after the job is removed
104
+ (Get-DbaAgentJob - SqlInstance $script :instance2 - Job " XE Session STOP - dbatoolsci_session_valid" ).Count | Should - Be 0
98
105
}
99
106
100
107
It " works when -StartAt is passed" {
101
108
$null = Stop-DbaXESession - SqlInstance $server - Session $dbatoolsciValid.Name - WarningAction SilentlyContinue
102
109
$StartAt = (Get-Date ).AddSeconds(10 )
103
- $session = Start-DbaXESession $server - Session $dbatoolsciValid.Name - StartAt $StartAt
104
- $session.IsRunning | Should Be $false
110
+ $null = Start-DbaXESession $server - Session $dbatoolsciValid.Name - StartAt $StartAt
111
+ $dbatoolsciValid.Refresh ()
112
+ $dbatoolsciValid.IsRunning | Should Be $false
105
113
(Get-DbaAgentJob - SqlInstance $server - Job " XE Session START - dbatoolsci_session_valid" ).Count | Should - Be 1
106
114
$startSchedule = Get-DbaAgentSchedule - SqlInstance $server - Schedule " XE Session START - dbatoolsci_session_valid"
107
115
$startSchedule.ActiveStartTimeOfDay.ToString (' hhmmss' ) | Should - Be $StartAt.TimeOfDay.ToString (' hhmmss' )
108
116
$startSchedule.ActiveStartDate | Should - Be $StartAt.Date
117
+ Start-Sleep - Seconds 11
118
+ $dbatoolsciValid.Refresh ()
119
+ $dbatoolsciValid.IsRunning | Should Be $true
120
+ # Using $script:instance2 because the SMO $server is not updated after the job is removed
121
+ (Get-DbaAgentJob - SqlInstance $script :instance2 - Job " XE Session STOP - dbatoolsci_session_valid" ).Count | Should - Be 0
109
122
}
110
123
111
124
}
0 commit comments