From d513bc1229c771633e62b8e23f8ae005b7d374d0 Mon Sep 17 00:00:00 2001 From: Mike Madeja Date: Mon, 28 Sep 2026 20:11:45 -0500 Subject: [PATCH] test: fix flaky Update-PiHoleClient tests missing a create-settle delay This test file's Update-PiHoleClient tests were failing intermittently in CI (3 times in a row across recent builds) with either a 400 on the Update-PiHoleClient call itself or a cascading "already exists" on the next test's New-PiHoleClient call. Every It block calls New-PiHoleClient immediately followed by Update-PiHoleClient with zero delay between them - the real Pi Zero W test server needs a moment to make a just-created client queryable/updatable again, the same known hardware limitation already worked around in tools/Update-ExampleOutput.ps1 for Lists/Domains/Groups, but this test file never got the same fix. Verified with a clean 7/7 pass against the real server after adding a short Start-Sleep between each New-PiHoleClient and the Update-PiHoleClient call that depends on it. Co-Authored-By: Claude Sonnet 5 --- .../Update-PiHoleClient.Integration.Tests.ps1 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/ClientManagement/Update-PiHoleClient.Integration.Tests.ps1 b/tests/ClientManagement/Update-PiHoleClient.Integration.Tests.ps1 index d3461de..b07af5d 100644 --- a/tests/ClientManagement/Update-PiHoleClient.Integration.Tests.ps1 +++ b/tests/ClientManagement/Update-PiHoleClient.Integration.Tests.ps1 @@ -38,6 +38,11 @@ Describe 'Update-PiHoleClient (Integration)' -Tag 'Integration' { It 'updates only the comment, preserving Group' -Skip:(-not $script:ConfigAvailable) { New-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient -Comment 'original comment' | Out-Null + # The test server takes a moment to make a just-added client queryable/updatable again - + # a real hardware limitation of this Pi Zero W, not a module bug (same settle-time + # reasoning as tools/Update-ExampleOutput.ps1 uses for Lists/Domains/Groups). + Start-Sleep -Seconds 2 + $result = Update-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient -Comment 'updated comment' $result | Format-List | Out-String | Write-Host @@ -51,6 +56,8 @@ Describe 'Update-PiHoleClient (Integration)' -Tag 'Integration' { It 'updates only Group, preserving the current comment' -Skip:(-not $script:ConfigAvailable) { New-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient -Comment 'keep this comment' | Out-Null + Start-Sleep -Seconds 2 + $result = Update-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient -Group $script:TestGroupName $result | Format-List | Out-String | Write-Host @@ -64,6 +71,8 @@ Describe 'Update-PiHoleClient (Integration)' -Tag 'Integration' { It 'errors when -Group names a group that does not exist' -Skip:(-not $script:ConfigAvailable) { New-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient | Out-Null + Start-Sleep -Seconds 2 + $result = Update-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient -Group 'DefinitelyNotARealGroup' -ErrorVariable errOut -ErrorAction SilentlyContinue Write-Host "Error ($($errOut.Count) entries, showing last): [$($errOut[-1])]" @@ -75,6 +84,8 @@ Describe 'Update-PiHoleClient (Integration)' -Tag 'Integration' { It 'returns the raw API response when RawOutput is set' -Skip:(-not $script:ConfigAvailable) { New-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient | Out-Null + Start-Sleep -Seconds 2 + $result = Update-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient -Comment 'raw output test' -RawOutput $true $result | Format-List | Out-String | Write-Host @@ -86,6 +97,8 @@ Describe 'Update-PiHoleClient (Integration)' -Tag 'Integration' { It 'errors when neither Comment nor Group is specified' -Skip:(-not $script:ConfigAvailable) { New-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient | Out-Null + Start-Sleep -Seconds 2 + $result = Update-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient -ErrorVariable errOut -ErrorAction SilentlyContinue $errOut | Should -Not -BeNullOrEmpty @@ -102,6 +115,8 @@ Describe 'Update-PiHoleClient (Integration)' -Tag 'Integration' { It 'errors when given a bad password' -Skip:(-not $script:ConfigAvailable) { New-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient | Out-Null + Start-Sleep -Seconds 2 + $result = Update-PiHoleClient -PiHoleServer $script:PiHoleServer -Password 'definitely-not-the-real-token' -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient -Comment 'irrelevant' -ErrorVariable errOut -ErrorAction SilentlyContinue $errOut | Should -Not -BeNullOrEmpty