Skip to content

Commit f2b4279

Browse files
Fix test for Start-DbaXESession (#9513)
1 parent 8b886a2 commit f2b4279

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

tests/Start-DbaXESession.Tests.ps1

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
5252
# Drop created objects
5353
$conn.ExecuteNonQuery("IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name = 'dbatoolsci_session_invalid') DROP EVENT SESSION [dbatoolsci_session_invalid] ON SERVER;")
5454
$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
5556
}
5657

5758
Context "Verifying command works" {
@@ -90,22 +91,34 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
9091
It "works when -StopAt is passed" {
9192
$StopAt = (Get-Date).AddSeconds(10)
9293
Start-DbaXESession $server -Session $dbatoolsciValid.Name -StopAt $StopAt -WarningAction SilentlyContinue
94+
$dbatoolsciValid.Refresh()
9395
$dbatoolsciValid.IsRunning | Should Be $true
9496
(Get-DbaAgentJob -SqlInstance $server -Job "XE Session STOP - dbatoolsci_session_valid").Count | Should -Be 1
9597
$stopSchedule = Get-DbaAgentSchedule -SqlInstance $server -Schedule "XE Session STOP - dbatoolsci_session_valid"
9698
$stopSchedule.ActiveStartTimeOfDay.ToString('hhmmss') | Should -Be $StopAt.TimeOfDay.ToString('hhmmss')
9799
$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
98105
}
99106

100107
It "works when -StartAt is passed" {
101108
$null = Stop-DbaXESession -SqlInstance $server -Session $dbatoolsciValid.Name -WarningAction SilentlyContinue
102109
$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
105113
(Get-DbaAgentJob -SqlInstance $server -Job "XE Session START - dbatoolsci_session_valid").Count | Should -Be 1
106114
$startSchedule = Get-DbaAgentSchedule -SqlInstance $server -Schedule "XE Session START - dbatoolsci_session_valid"
107115
$startSchedule.ActiveStartTimeOfDay.ToString('hhmmss') | Should -Be $StartAt.TimeOfDay.ToString('hhmmss')
108116
$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
109122
}
110123

111124
}

0 commit comments

Comments
 (0)