Skip to content

Commit

Permalink
Merge branch '6.4' into 7.0
Browse files Browse the repository at this point in the history
* 6.4:
  [TwigBridge] foundation 5 layout: use form_label_content block for checkbox and radio labels
  [TwigBridge] Fix compat with Twig v3.9
  [Cache] Sync the Redis proxies with upstream
  [Doctrine Messenger] Fix support for pgsql + pgbouncer.
  [Mailer] Simplify fix
  Do not produce notice/warning when consuming from multiple transports and explicitly listed queues
  [FrameworkBundle] Check if the _route attribute exists on the request
  [Scheduler] fix documentation link
  [PropertyAccess] Fixes getValue() on an unitialized object property on a lazy ghost
  [HttpClient] Make retry strategy work again
  AssetMapper: Remove 'auto-generated' info
  [Mailer] Fix signed emails breaking the profiler
  [Mailer] [Mailgun] Fix expecting payload without tags or user variables
  [Validator] Update Spanish (es) translations
  Fix fetching data in `W3CReferenceTest` on AppVeyor
  Fix SQS visibility_timeout type
  [VarDumper] Fix serialization of stubs with null or uninitialized values
  • Loading branch information
nicolas-grekas committed Feb 15, 2024
2 parents 3d2605c + aa6281d commit 8384876
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
3 changes: 2 additions & 1 deletion Response/AsyncResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public function __construct(HttpClientInterface $client, string $method, string
while (true) {
foreach (self::stream([$response], $timeout) as $chunk) {
if ($chunk->isTimeout() && $response->passthru) {
foreach (self::passthru($response->client, $response, new ErrorChunk($response->offset, $chunk->getError())) as $chunk) {
// Timeouts thrown during initialization are transport errors
foreach (self::passthru($response->client, $response, new ErrorChunk($response->offset, new TransportException($chunk->getError()))) as $chunk) {
if ($chunk->isFirst()) {
return false;
}
Expand Down
41 changes: 23 additions & 18 deletions Tests/RetryableHttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\Exception\ServerException;
use Symfony\Component\HttpClient\Exception\TimeoutException;
use Symfony\Component\HttpClient\Exception\TransportException;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\NativeHttpClient;
use Symfony\Component\HttpClient\Response\AsyncContext;
use Symfony\Component\HttpClient\Response\MockResponse;
use Symfony\Component\HttpClient\Retry\GenericRetryStrategy;
use Symfony\Component\HttpClient\Retry\RetryStrategyInterface;
use Symfony\Component\HttpClient\RetryableHttpClient;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\Test\TestHttpServer;
Expand Down Expand Up @@ -247,33 +248,37 @@ public function testRetryOnErrorAssertContent()
self::assertSame('Test out content', $response->getContent(), 'Content should be buffered');
}

/**
* @testWith ["GET"]
* ["POST"]
* ["PUT"]
* ["PATCH"]
* ["DELETE"]
*/
public function testRetryOnHeaderTimeout(string $method)
public function testRetryOnTimeout()
{
$client = HttpClient::create();

if ($client instanceof NativeHttpClient) {
$this->markTestSkipped('NativeHttpClient cannot timeout before receiving headers');
}

TestHttpServer::start();

$client = new RetryableHttpClient($client);
$response = $client->request($method, 'http://localhost:8057/timeout-header', ['timeout' => 0.1]);
$strategy = new class() implements RetryStrategyInterface {
public $isCalled = false;

public function shouldRetry(AsyncContext $context, ?string $responseContent, ?TransportExceptionInterface $exception): ?bool
{
$this->isCalled = true;

return false;
}

public function getDelay(AsyncContext $context, ?string $responseContent, ?TransportExceptionInterface $exception): int
{
return 0;
}
};
$client = new RetryableHttpClient($client, $strategy);
$response = $client->request('GET', 'http://localhost:8057/timeout-header', ['timeout' => 0.1]);

try {
$response->getStatusCode();
$this->fail(TimeoutException::class.' expected');
} catch (TimeoutException $e) {
$this->fail(TransportException::class.' expected');
} catch (TransportException $e) {
}

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

public function testRetryWithMultipleBaseUris()
Expand Down

0 comments on commit 8384876

Please sign in to comment.