Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b365e3a

Browse filesBrowse files
committed
[HttpClient] Make retry strategy work again
Reverts #53506
1 parent f99dfe5 commit b365e3a
Copy full SHA for b365e3a

File tree

Expand file treeCollapse file tree

2 files changed

+22
-12
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-12
lines changed

‎src/Symfony/Component/HttpClient/Response/AsyncResponse.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/AsyncResponse.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function __construct(HttpClientInterface $client, string $method, string
6565
while (true) {
6666
foreach (self::stream([$response], $timeout) as $chunk) {
6767
if ($chunk->isTimeout() && $response->passthru) {
68-
foreach (self::passthru($response->client, $response, new ErrorChunk($response->offset, $chunk->getError())) as $chunk) {
68+
foreach (self::passthru($response->client, $response, new ErrorChunk($response->offset, new TransportException($chunk->getError()))) as $chunk) {
6969
if ($chunk->isFirst()) {
7070
return false;
7171
}

‎src/Symfony/Component/HttpClient/Tests/RetryableHttpClientTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Tests/RetryableHttpClientTest.php
+21-11Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\HttpClient\Exception\ServerException;
1616
use Symfony\Component\HttpClient\Exception\TimeoutException;
17+
use Symfony\Component\HttpClient\Exception\TransportException;
1718
use Symfony\Component\HttpClient\HttpClient;
1819
use Symfony\Component\HttpClient\MockHttpClient;
1920
use Symfony\Component\HttpClient\NativeHttpClient;
2021
use Symfony\Component\HttpClient\Response\AsyncContext;
2122
use Symfony\Component\HttpClient\Response\MockResponse;
2223
use Symfony\Component\HttpClient\Retry\GenericRetryStrategy;
24+
use Symfony\Component\HttpClient\Retry\RetryStrategyInterface;
2325
use Symfony\Component\HttpClient\RetryableHttpClient;
2426
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
2527
use Symfony\Contracts\HttpClient\Test\TestHttpServer;
@@ -248,13 +250,9 @@ public function testRetryOnErrorAssertContent()
248250
}
249251

250252
/**
251-
* @testWith ["GET"]
252-
* ["POST"]
253-
* ["PUT"]
254-
* ["PATCH"]
255-
* ["DELETE"]
253+
* Make sure we use the RetryableHttpClient on timeouts
256254
*/
257-
public function testRetryOnHeaderTimeout(string $method)
255+
public function testRetryOnTimeout()
258256
{
259257
$client = HttpClient::create();
260258

@@ -264,15 +262,27 @@ public function testRetryOnHeaderTimeout(string $method)
264262

265263
TestHttpServer::start();
266264

267-
$client = new RetryableHttpClient($client);
268-
$response = $client->request($method, 'http://localhost:8057/timeout-header', ['timeout' => 0.1]);
265+
$strategy = new class implements RetryStrategyInterface {
266+
public $isCalled = false;
267+
public function shouldRetry(AsyncContext $context, ?string $responseContent, ?TransportExceptionInterface $exception): ?bool
268+
{
269+
$this->isCalled = true;
270+
return false;
271+
}
272+
273+
public function getDelay(AsyncContext $context, ?string $responseContent, ?TransportExceptionInterface $exception): int
274+
{
275+
return 0;
276+
}
277+
};
278+
$client = new RetryableHttpClient($client, $strategy);
279+
$response = $client->request('GET', 'http://localhost:8057/timeout-header', ['timeout' => 0.1]);
269280

270281
try {
271282
$response->getStatusCode();
272-
$this->fail(TimeoutException::class.' expected');
273-
} catch (TimeoutException $e) {
283+
} catch (TransportException $e) {
274284
}
275285

276-
$this->assertSame('Idle timeout reached for "http://localhost:8057/timeout-header".', $response->getInfo('error'));
286+
$this->assertTrue($strategy->isCalled, 'The HTTP retry strategy should be called');
277287
}
278288
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.