Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app-runner/Private/RetryPolicy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ $script:RetryPolicyRegistry = @{}
# See <https://docs.saucelabs.com/dev/error-messages/> for the complete error catalog.
# Only fatal: add a message only after confirming that retrying cannot resolve it.
$script:SauceLabsFatalSessionMessages = @(
"we couldn't find a matching device in our data center",
"we couldn't find a matching device in our* data center",
"sauce labs virtual machine failed to start the browser or device"
)

Expand Down
31 changes: 29 additions & 2 deletions app-runner/Tests/HttpRetry.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,40 @@ Describe 'Invoke-HttpWithRetry' -Tag 'Unit' {
}

Context 'Session policy classification' {
It 'Retries a temporary device availability failure' {
It 'Does not retry a missing matching device in <DataCenter>' -TestCases @(
@{ DataCenter = 'our data center' }
@{ DataCenter = 'our US-West data center' }
@{ DataCenter = 'our US-East data center' }
@{ DataCenter = 'our EU-Central data center' }
) {
param($DataCenter)

$script:attempts = 0
$body = @{ value = @{ message = "We couldn't find a MATCHING device in $DataCenter that matches your requested capabilities: - deviceName: iPhone_17_*_real_sjc1 - platformName: iOS" } } | ConvertTo-Json -Compress

{
Invoke-HttpWithRetry -Operation 'POST /session' -Policy (Get-RetryPolicy 'sauce-session') -SleepAction {} -ScriptBlock {
$script:attempts++
throw (New-HttpErrorRecord -StatusCode 500 -Body '{"value":{"message":"We couldn''t find an available device in our data center that matches your requested capabilities."}}')
throw (New-HttpErrorRecord -StatusCode 500 -Body $body)
}
} | Should -Throw

$script:attempts | Should -Be 1
}

It 'Retries a temporary device availability failure in <DataCenter>' -TestCases @(
@{ DataCenter = 'our data center' }
@{ DataCenter = 'our US-West data center' }
) {
param($DataCenter)

$script:attempts = 0
$body = @{ value = @{ message = "We couldn't find an available device in $DataCenter that matches your requested capabilities." } } | ConvertTo-Json -Compress

{
Invoke-HttpWithRetry -Operation 'POST /session' -Policy (Get-RetryPolicy 'sauce-session') -SleepAction {} -ScriptBlock {
$script:attempts++
throw (New-HttpErrorRecord -StatusCode 500 -Body $body)
}
} | Should -Throw

Expand Down
Loading