Skip to content

Commit 5c671a1

Browse files
Harden Organizations tests against transient API failures
Agent-Logs-Url: https://github.com/PSModule/GitHub/sessions/4544dc21-9d62-448f-b51c-16fb320e09af Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
1 parent 92611a8 commit 5c671a1

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

tests/Organizations.Tests.ps1

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ Describe 'Organizations' {
7979
# GITHUB_RUN_ATTEMPT remain idempotent.
8080
$staleOrgs = @()
8181
foreach ($candidateName in $orgNamesToCheck) {
82-
$candidateOrg = Get-GitHubOrganization -Name $candidateName -ErrorAction SilentlyContinue
82+
try {
83+
$candidateOrg = Get-GitHubOrganization -Name $candidateName -ErrorAction SilentlyContinue
84+
} catch {
85+
Write-Host "Could not inspect candidate stale org [$candidateName]: $($_.Exception.Message)"
86+
continue
87+
}
8388
if ($candidateOrg -and $candidateOrg.Name) {
8489
$staleOrgs += $candidateOrg
8590
}
@@ -303,7 +308,24 @@ Describe 'Organizations' {
303308
It 'Remove-GitHubOrganizationInvitation - Removes a user invitation from an organization' {
304309
{
305310
$invitation = Get-GitHubOrganizationPendingInvitation -Organization $owner | Select-Object -First 1
306-
Remove-GitHubOrganizationInvitation -Organization $owner -ID $invitation.id
311+
$maxAttempts = 5
312+
$retryDelay = 3
313+
for ($retryAttempt = 1; $retryAttempt -le $maxAttempts; $retryAttempt++) {
314+
try {
315+
Remove-GitHubOrganizationInvitation -Organization $owner -ID $invitation.id -ErrorAction Stop
316+
break
317+
} catch {
318+
if (
319+
$retryAttempt -lt $maxAttempts -and
320+
$_.Exception.Message -match '502'
321+
) {
322+
Write-Host "Remove-GitHubOrganizationInvitation attempt $retryAttempt/$maxAttempts failed: $($_.Exception.Message). Retrying in ${retryDelay}s..."
323+
Start-Sleep -Seconds $retryDelay
324+
} else {
325+
throw
326+
}
327+
}
328+
}
307329
} | Should -Not -Throw
308330
}
309331
}

0 commit comments

Comments
 (0)