Skip to content

Commit

Permalink
update test (do Start-DbaXESession)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasjordan committed Oct 14, 2024
1 parent f0423f5 commit ca39366
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions tests/Start-DbaXESession.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
# Drop created objects
$conn.ExecuteNonQuery("IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name = 'dbatoolsci_session_invalid') DROP EVENT SESSION [dbatoolsci_session_invalid] ON SERVER;")
$conn.ExecuteNonQuery("IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name = 'dbatoolsci_session_valid') DROP EVENT SESSION [dbatoolsci_session_valid] ON SERVER;")
Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule "XE Session START - dbatoolsci_session_valid", "XE Session STOP - dbatoolsci_session_valid" | Remove-DbaAgentSchedule -Force -Confirm:$false
}

Context "Verifying command works" {
Expand Down Expand Up @@ -90,22 +91,34 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
It "works when -StopAt is passed" {
$StopAt = (Get-Date).AddSeconds(10)
Start-DbaXESession $server -Session $dbatoolsciValid.Name -StopAt $StopAt -WarningAction SilentlyContinue
$dbatoolsciValid.Refresh()
$dbatoolsciValid.IsRunning | Should Be $true
(Get-DbaAgentJob -SqlInstance $server -Job "XE Session STOP - dbatoolsci_session_valid").Count | Should -Be 1
$stopSchedule = Get-DbaAgentSchedule -SqlInstance $server -Schedule "XE Session STOP - dbatoolsci_session_valid"
$stopSchedule.ActiveStartTimeOfDay.ToString('hhmmss') | Should -Be $StopAt.TimeOfDay.ToString('hhmmss')
$stopSchedule.ActiveStartDate | Should -Be $StopAt.Date
Start-Sleep -Seconds 11
$dbatoolsciValid.Refresh()
$dbatoolsciValid.IsRunning | Should Be $false
# Using $script:instance2 because the SMO $server is not updated after the job is removed
(Get-DbaAgentJob -SqlInstance $script:instance2 -Job "XE Session STOP - dbatoolsci_session_valid").Count | Should -Be 0
}

It "works when -StartAt is passed" {
$null = Stop-DbaXESession -SqlInstance $server -Session $dbatoolsciValid.Name -WarningAction SilentlyContinue
$StartAt = (Get-Date).AddSeconds(10)
$session = Start-DbaXESession $server -Session $dbatoolsciValid.Name -StartAt $StartAt
$session.IsRunning | Should Be $false
$null = Start-DbaXESession $server -Session $dbatoolsciValid.Name -StartAt $StartAt
$dbatoolsciValid.Refresh()
$dbatoolsciValid.IsRunning | Should Be $false
(Get-DbaAgentJob -SqlInstance $server -Job "XE Session START - dbatoolsci_session_valid").Count | Should -Be 1
$startSchedule = Get-DbaAgentSchedule -SqlInstance $server -Schedule "XE Session START - dbatoolsci_session_valid"
$startSchedule.ActiveStartTimeOfDay.ToString('hhmmss') | Should -Be $StartAt.TimeOfDay.ToString('hhmmss')
$startSchedule.ActiveStartDate | Should -Be $StartAt.Date
Start-Sleep -Seconds 11
$dbatoolsciValid.Refresh()
$dbatoolsciValid.IsRunning | Should Be $true
# Using $script:instance2 because the SMO $server is not updated after the job is removed
(Get-DbaAgentJob -SqlInstance $script:instance2 -Job "XE Session STOP - dbatoolsci_session_valid").Count | Should -Be 0
}

}
Expand Down

0 comments on commit ca39366

Please sign in to comment.