Skip to content

Commit 14a9dce

Browse files
authored
Strengthen teardown timeout diagnostics and APIM lookup
1 parent 57a249b commit 14a9dce

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

tests/integration/all-resource-types/phases/run-phase7-teardown.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,16 @@ function Wait-ForResourceGroupsDeletion {
8282
$waitedSeconds += $IntervalSeconds
8383
}
8484

85-
throw "Timed out waiting for resource group deletion."
85+
$maskedGroups = $ResourceGroups | ForEach-Object { Protect-ResourceGroupName -Value $_ }
86+
throw "Timed out waiting for resource group deletion for: $($maskedGroups -join ', ')."
8687
}
8788

8889
function Wait-ForDeletedApimService {
8990
param(
9091
[Parameter(Mandatory)]
9192
[string]$ServiceName,
93+
[Parameter(Mandatory)]
94+
[string]$ServiceLocation,
9295
[int]$TimeoutMinutes = 30,
9396
[int]$IntervalSeconds = 15
9497
)
@@ -97,11 +100,8 @@ function Wait-ForDeletedApimService {
97100
$timeoutSeconds = $TimeoutMinutes * 60
98101

99102
while ($waitedSeconds -lt $timeoutSeconds) {
100-
$matchingDeletedServicesCount = az apim deletedservice list --query "[?name=='$ServiceName'] | length(@)" -o tsv 2>$null
101-
$deletedServicesCount = 0
102-
$null = [int]::TryParse($matchingDeletedServicesCount, [ref]$deletedServicesCount)
103-
104-
if ($deletedServicesCount -gt 0) {
103+
az apim deletedservice show --service-name $ServiceName --location $ServiceLocation -o none 2>$null
104+
if ($LASTEXITCODE -eq 0) {
105105
return
106106
}
107107

@@ -110,7 +110,7 @@ function Wait-ForDeletedApimService {
110110
$waitedSeconds += $IntervalSeconds
111111
}
112112

113-
throw "Timed out waiting for APIM soft-delete entry for '$(Protect-ApimName -Value $ServiceName)'."
113+
throw "Timed out waiting for APIM soft-delete entry for '$(Protect-ApimName -Value $ServiceName)' in location '$ServiceLocation'."
114114
}
115115

116116
Write-Host " Deleting $(Protect-ResourceGroupName -Value $SourceResourceGroup)..."
@@ -122,13 +122,13 @@ Write-Host " ⏳ Waiting for resource group deletions to complete for hard-del
122122
Wait-ForResourceGroupsDeletion -ResourceGroups @($SourceResourceGroup, $TargetResourceGroup)
123123

124124
if ($sourceApimName) {
125-
Wait-ForDeletedApimService -ServiceName $sourceApimName
125+
Wait-ForDeletedApimService -ServiceName $sourceApimName -ServiceLocation $Location
126126
Write-Host " 🗑️ Purging soft-deleted APIM: $(Protect-ApimName -Value $sourceApimName)..."
127127
az apim deletedservice purge --service-name $sourceApimName --location $Location 2>$null
128128
}
129129

130130
if ($targetApimName) {
131-
Wait-ForDeletedApimService -ServiceName $targetApimName
131+
Wait-ForDeletedApimService -ServiceName $targetApimName -ServiceLocation $Location
132132
Write-Host " 🗑️ Purging soft-deleted APIM: $(Protect-ApimName -Value $targetApimName)..."
133133
az apim deletedservice purge --service-name $targetApimName --location $Location 2>$null
134134
}

0 commit comments

Comments
 (0)