Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test for Start-DbaXESession #9513

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
niphlod marked this conversation as resolved.
Show resolved Hide resolved
$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
Loading