Skip to content

Commit

Permalink
Merge branch '5.4' into 6.3
Browse files Browse the repository at this point in the history
* 5.4:
  [HttpClient] Fix pausing responses before they start when using curl
  separate child and parent context in NotificationEmail on writes
  do not overwrite the cache key when it is false
  [Mailer] Throw TransportException when unable to read from socket
  [Serializer] Rewrite `AbstractObjectNormalizer::createChildContext()` to use the provided `cache_key` from original context when creating child contexts
  [HttpClient] Fix error chunk creation in passthru
  Adjusting and removing the 'review' attribute from the pt_br translation XML.
  [Serializer] Take unnamed variadic parameters into account when denormalizing
  • Loading branch information
nicolas-grekas committed Jan 29, 2024
2 parents 5b7fa7e + 53e4cc0 commit 510c510
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Response/AsyncResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ 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, new TransportException($chunk->getError()))) as $chunk) {
foreach (self::passthru($response->client, $response, new ErrorChunk($response->offset, $chunk->getError())) as $chunk) {
if ($chunk->isFirst()) {
return false;
}
Expand Down
1 change: 0 additions & 1 deletion Response/CurlResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public function __construct(CurlClientState $multi, \CurlHandle|string $ch, ?arr
$this->info['pause_handler'] = static function (float $duration) use ($ch, $multi, $execCounter) {
if (0 < $duration) {
if ($execCounter === $multi->execCounter) {
$multi->execCounter = !\is_float($execCounter) ? 1 + $execCounter : \PHP_INT_MIN;
curl_multi_remove_handle($multi->handle, $ch);
}

Expand Down
31 changes: 31 additions & 0 deletions Tests/RetryableHttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\Exception\ServerException;
use Symfony\Component\HttpClient\Exception\TimeoutException;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\NativeHttpClient;
Expand All @@ -21,6 +22,7 @@
use Symfony\Component\HttpClient\Retry\GenericRetryStrategy;
use Symfony\Component\HttpClient\RetryableHttpClient;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\Test\TestHttpServer;

class RetryableHttpClientTest extends TestCase
{
Expand Down Expand Up @@ -245,6 +247,35 @@ 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)
{
$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]);

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

$this->assertSame('Idle timeout reached for "http://localhost:8057/timeout-header".', $response->getInfo('error'));
}

public function testRetryWithMultipleBaseUris()
{
$client = new RetryableHttpClient(
Expand Down

0 comments on commit 510c510

Please sign in to comment.