Skip to content
Open
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
6 changes: 4 additions & 2 deletions Storage/src/Connection/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,15 @@ public function headObject(array $args = []): array
'prettyPrint' => false,
];

$args['retryStrategy'] ??= $this->retryStrategy;

$args['restRetryFunction'] = $this->restRetryFunction ?? $this->getRestRetryFunction(
'objects',
'get',
$args
);

$args += array_filter([
'retryStrategy' => $this->retryStrategy,
'restDelayFunction' => $this->restDelayFunction,
'restCalcDelayFunction' => $this->restCalcDelayFunction,
'restRetryListener' => $this->restRetryListener,
Expand Down Expand Up @@ -1023,14 +1024,15 @@ public function send($resource, $method, array $options = [], $whitelisted = fal
];
$retryResource = isset($retryMap[$resource]) ? $retryMap[$resource] : $resource;

$options['retryStrategy'] ??= $this->retryStrategy;

$options['restRetryFunction'] = $this->restRetryFunction ?? $this->getRestRetryFunction(
$retryResource,
$method,
$options
);

$options += array_filter([
'retryStrategy' => $this->retryStrategy,
'restDelayFunction' => $this->restDelayFunction,
'restCalcDelayFunction' => $this->restCalcDelayFunction,
'restRetryListener' => $this->restRetryListener,
Expand Down
26 changes: 26 additions & 0 deletions Storage/tests/Unit/StorageClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,32 @@ public function testAlwaysRetryStrategySuccessful()
$this->assertInstanceOf(Bucket::class, $client->createBucket('myBucket'));
}

public function testAlwaysRetryStrategyWithNonIdempotentOpSuccessful()
{
$httpHandler = self::getHttpHandlerMock([
new Response(503), // Service Unavailable
new Response(200, [], ''), // Successful delete
])[1];

$client = new StorageClient([
'projectId' => self::PROJECT,
'retryStrategy' => StorageClient::RETRY_ALWAYS,
// Mock the httpHandler so it doesn't make a real request
'httpHandler' => $httpHandler,
// Mock the authHttpHandler so it doesn't make a real request
Comment thread
salilg-eng marked this conversation as resolved.
'authHttpHandler' => function () {
return new Response(200, [], '{"access_token": "abc"}');
},
// Mock the delay function so the tests execute faster
'restDelayFunction' => function () {
},
]);

$bucket = $client->bucket('myBucket');
$bucket->object('myObject')->delete();
$this->assertTrue(true); // If no exception was thrown, we succeeded.
}

public function testDelayFunctionsConfiguration()
{
$httpHandler = self::getHttpHandlerMock([
Expand Down
Loading