From 5814142e9de9eb8ced192d9bcaf05e0741903a9c Mon Sep 17 00:00:00 2001 From: andreasjordan Date: Sun, 21 Jul 2024 08:39:10 +0200 Subject: [PATCH 1/2] Fix bug (do Get-DbaLatchStatistic) --- public/Get-DbaLatchStatistic.ps1 | 4 ++-- tests/pester.groups.ps1 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/public/Get-DbaLatchStatistic.ps1 b/public/Get-DbaLatchStatistic.ps1 index 69d767cb6f..59a48208a0 100644 --- a/public/Get-DbaLatchStatistic.ps1 +++ b/public/Get-DbaLatchStatistic.ps1 @@ -95,7 +95,7 @@ function Get-DbaLatchStatistic { [latch_class], [wait_time_ms] / 1000.0 AS [WaitS], [waiting_requests_count] AS [WaitCount], - Case WHEN SUM ([wait_time_ms]) OVER() = 0 THEN NULL ELSE 100.0 * [wait_time_ms] / SUM ([wait_time_ms]) OVER() END AS [Percentage], + CASE WHEN SUM([wait_time_ms]) OVER() > 0 THEN 100.0 * [wait_time_ms] / SUM([wait_time_ms]) OVER() END AS [Percentage], ROW_NUMBER() OVER(ORDER BY [wait_time_ms] DESC) AS [RowNum] FROM sys.dm_os_latch_stats WHERE [latch_class] NOT IN (N'BUFFER') @@ -105,7 +105,7 @@ function Get-DbaLatchStatistic { CAST (MAX ([W1].[WaitS]) AS DECIMAL(14, 2)) AS [WaitSeconds], MAX ([W1].[WaitCount]) AS [WaitCount], CAST (MAX ([W1].[Percentage]) AS DECIMAL(14, 2)) AS [Percentage], - CAST ((MAX ([W1].[WaitS]) / MAX ([W1].[WaitCount])) AS DECIMAL (14, 4)) AS [AvgWaitSeconds], + CAST (CASE WHEN MAX([W1].[WaitCount]) > 0 THEN MAX([W1].[WaitS]) / MAX([W1].[WaitCount]) END AS DECIMAL (14, 4)) AS [AvgWaitSeconds], CAST ('https://www.sqlskills.com/help/latches/' + MAX ([W1].[latch_class]) as XML) AS [URL] FROM [Latches] AS [W1] INNER JOIN [Latches] AS [W2] diff --git a/tests/pester.groups.ps1 b/tests/pester.groups.ps1 index 8599d1f9f8..39f5379c6e 100644 --- a/tests/pester.groups.ps1 +++ b/tests/pester.groups.ps1 @@ -28,7 +28,7 @@ $TestsRunGroups = @{ 'Get-DbaExecutionPlan', # Non-useful info from newly started sql servers 'Get-DbaCpuRingBuffer', - 'Get-DbaLatchStatistic', + #'Get-DbaLatchStatistic', # times out 'Copy-DbaResourceGovernor', # fails on newer version of SMO From 82f866bc946aac0a6d2d1124a1ba9e314fbf6233 Mon Sep 17 00:00:00 2001 From: andreasjordan Date: Sun, 21 Jul 2024 09:04:52 +0200 Subject: [PATCH 2/2] continue to skip test on appveyor --- tests/pester.groups.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pester.groups.ps1 b/tests/pester.groups.ps1 index 39f5379c6e..8599d1f9f8 100644 --- a/tests/pester.groups.ps1 +++ b/tests/pester.groups.ps1 @@ -28,7 +28,7 @@ $TestsRunGroups = @{ 'Get-DbaExecutionPlan', # Non-useful info from newly started sql servers 'Get-DbaCpuRingBuffer', - #'Get-DbaLatchStatistic', + 'Get-DbaLatchStatistic', # times out 'Copy-DbaResourceGovernor', # fails on newer version of SMO