From f89d84604a19b24257d4954c5dc39eacdc9cb030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20De=20Francesco?= Date: Mon, 16 Nov 2026 16:25:02 -0300 Subject: [PATCH] Tolerate a recreated Service Fabric app not yet deployed on its node in the stability check Co-Authored-By: Claude Sonnet 5.5 --- .../Assert-ServiceFabricApplicationStable.ps1 | 23 ++++++++++++++++--- .../tests/Test-ServiceFabricStability.ps1 | 18 +++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/.github/actions/verify-servicefabric-stable/Assert-ServiceFabricApplicationStable.ps1 b/.github/actions/verify-servicefabric-stable/Assert-ServiceFabricApplicationStable.ps1 index 5e4241d..11bd12b 100644 --- a/.github/actions/verify-servicefabric-stable/Assert-ServiceFabricApplicationStable.ps1 +++ b/.github/actions/verify-servicefabric-stable/Assert-ServiceFabricApplicationStable.ps1 @@ -48,17 +48,34 @@ function Get-SfStabilitySnapshot { } } } + $notDeployedOn = @() foreach ($node in @($nodes.Keys)) { - foreach ($package in @(Get-ServiceFabricDeployedCodePackage -NodeName $node -ApplicationName $Application -ErrorAction Stop)) { + # Right after the application is created or recreated, a node can already hold a replica while the application is + # not yet activated there, and the query answers "Application not found". That is a transient state of a deployment + # in progress, so report it as a non-Ok snapshot (the check keeps waiting) instead of aborting the check. + try { + $packages = @(Get-ServiceFabricDeployedCodePackage -NodeName $node -ApplicationName $Application -ErrorAction Stop) + } catch { + if ($_.Exception.GetType().Name -ne 'FabricElementNotFoundException') { throw } + $notDeployedOn += $node + continue + } + foreach ($package in $packages) { $entryPoint = $package.EntryPoint if ($null -eq $entryPoint) { continue } $activation = if ($package.PSObject.Properties['ServicePackageActivationId']) { $package.ServicePackageActivationId } else { '' } $identities["process $node $($package.ServiceManifestName) $($package.CodePackageName) $activation"] = "$($entryPoint.InstanceId)/$($entryPoint.ProcessId)" } } + $state = [string]$health.AggregatedHealthState + $details = Get-SfHealthDetails $health + if ($notDeployedOn.Count -gt 0) { + $state = 'NotDeployed' + $details = @("application not yet deployed on node(s): $($notDeployedOn -join ', ')") + $details + } return [pscustomobject]@{ - Health = [string]$health.AggregatedHealthState - Details = Get-SfHealthDetails $health + Health = $state + Details = $details Identities = $identities } } diff --git a/.github/actions/verify-servicefabric-stable/tests/Test-ServiceFabricStability.ps1 b/.github/actions/verify-servicefabric-stable/tests/Test-ServiceFabricStability.ps1 index 2627d7d..e7e1268 100644 --- a/.github/actions/verify-servicefabric-stable/tests/Test-ServiceFabricStability.ps1 +++ b/.github/actions/verify-servicefabric-stable/tests/Test-ServiceFabricStability.ps1 @@ -31,6 +31,24 @@ Assert-Result (Invoke-Scenario @((New-Snapshot Ok), (New-Snapshot Ok '200'))) $f Assert-Result (Invoke-Scenario @((New-Snapshot Ok), (New-Snapshot Ok), (New-Snapshot Error))) $false 'HealthError' $true 'ErrorInWindowFailsAndRollsBack' Assert-Result (Invoke-Scenario @((New-Snapshot Ok), (New-Snapshot Warning))) $false 'HealthWarning' $false 'WarningInWindowFailsWithoutRollback' Assert-Result (Invoke-Scenario @((New-Snapshot Warning)) -ReadyTimeoutSeconds 20) $false 'NeverOk' $false 'PersistentWarningFailsWithoutRollback' +Assert-Result (Invoke-Scenario @((New-Snapshot NotDeployed), (New-Snapshot NotDeployed), (New-Snapshot Ok))) $true 'Stable' $false 'RecreatedApplicationNotYetDeployedIsTolerated' +Assert-Result (Invoke-Scenario @((New-Snapshot NotDeployed)) -ReadyTimeoutSeconds 30) $false 'NeverOk' $false 'NeverDeployedStillFails' + +# Get-SfStabilitySnapshot must turn "Application not found" on a node into a NotDeployed snapshot and rethrow anything else. +function Get-ServiceFabricApplicationHealth { [pscustomobject]@{ AggregatedHealthState = 'Ok'; UnhealthyEvaluations = @() } } +function Get-ServiceFabricService { [pscustomobject]@{ ServiceName = 'fabric:/Fixture/svc' } } +function Get-ServiceFabricPartition { [pscustomobject]@{ PartitionId = [guid]::Empty } } +function Get-ServiceFabricReplica { [pscustomobject]@{ NodeName = 'vm1'; ReplicaId = 7 } } +Add-Type -TypeDefinition 'public class FabricElementNotFoundException : System.Exception { public FabricElementNotFoundException(string m) : base(m) {} }' +function Get-ServiceFabricDeployedCodePackage { throw [FabricElementNotFoundException]::new('Application not found') } +$snapshot = Get-SfStabilitySnapshot -Application 'fabric:/Fixture' +if ($snapshot.Health -ne 'NotDeployed') { throw "Snapshot of a not yet deployed application must be NotDeployed, got $($snapshot.Health)." } +Write-Host 'PASS SnapshotReportsNotDeployed' +function Get-ServiceFabricDeployedCodePackage { throw 'boom' } +$threw = $false +try { Get-SfStabilitySnapshot -Application 'fabric:/Fixture' | Out-Null } catch { $threw = $true } +if (-not $threw) { throw 'Other errors must still abort the snapshot.' } +Write-Host 'PASS OtherSnapshotErrorsStillThrow' $changes = Compare-SfIdentities -Baseline @{ a = '1'; b = '2' } -Current @{ a = '1'; c = '3' } if ($changes.Count -ne 2) { throw 'Identity comparison must report removed and added replicas.' }