From c03dc6526a0523800110d3a17f660b509c16fde7 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Mon, 28 Oct 2024 20:48:39 +0100 Subject: [PATCH] lets see if this :poop: works! --- tests/Get-DbaDbccSessionBuffer.Tests.ps1 | 41 +++++++++++++++++------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/tests/Get-DbaDbccSessionBuffer.Tests.ps1 b/tests/Get-DbaDbccSessionBuffer.Tests.ps1 index 61538a8f3e..ab4e424b59 100644 --- a/tests/Get-DbaDbccSessionBuffer.Tests.ps1 +++ b/tests/Get-DbaDbccSessionBuffer.Tests.ps1 @@ -34,9 +34,38 @@ Describe "Get-DbaDbccSessionBuffer" -Tag "UnitTests" { Describe "Get-DbaDbccSessionBuffer" -Tag "IntegrationTests" { BeforeAll { $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database tempdb + # Create a query that will generate buffer data + $query = @" + DECLARE @i INT = 0; + WHILE @i < 10 BEGIN + SELECT TOP 100 * FROM sys.objects; + SET @i = @i + 1; + WAITFOR DELAY '00:00:01'; + END; +"@ + # Start the query in a background runspace to ensure it's running during our tests + $script:runspace = [powershell]::Create().AddScript({ + param($instance, $query) + Import-Module dbatools + $db = Get-DbaDatabase -SqlInstance $instance -Database tempdb + $db.Query($query) + }).AddArgument($TestConfig.instance1).AddArgument($query) + + $script:runspaceHandle = $script:runspace.BeginInvoke() + Start-Sleep -Seconds 2 # Give the query time to start + $queryResult = $db.Query('SELECT top 10 object_id, @@Spid as MySpid FROM sys.objects') } + AfterAll { + if ($script:runspace) { + if (-not $script:runspaceHandle.IsCompleted) { + $script:runspace.Stop() + } + $script:runspace.Dispose() + } + } + Context "When getting session buffers for all databases" { BeforeAll { $inputProps = @( @@ -48,14 +77,6 @@ Describe "Get-DbaDbccSessionBuffer" -Tag "IntegrationTests" { 'Parameters', 'EventInfo' ) - $outputProps = @( - 'ComputerName', - 'InstanceName', - 'SqlInstance', - 'SessionId', - 'Buffer', - 'HexBuffer' - ) $resultInput = Get-DbaDbccSessionBuffer -SqlInstance $TestConfig.instance1 -Operation InputBuffer -All $resultOutput = Get-DbaDbccSessionBuffer -SqlInstance $TestConfig.instance1 -Operation OutputBuffer -All } @@ -71,10 +92,6 @@ Describe "Get-DbaDbccSessionBuffer" -Tag "IntegrationTests" { It "Returns results for OutputBuffer" { $resultOutput.Count | Should -BeGreaterThan 0 } - - It "Has property <_> for OutputBuffer" -ForEach $outputProps { - $resultOutput[0].PSObject.Properties[$PSItem].Name | Should -Be $PSItem - } } Context "When getting session buffers for specific SessionId" {