|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\HttpClient\Exception\ServerException;
|
| 16 | +use Symfony\Component\HttpClient\Exception\TimeoutException; |
16 | 17 | use Symfony\Component\HttpClient\HttpClient;
|
17 | 18 | use Symfony\Component\HttpClient\MockHttpClient;
|
18 | 19 | use Symfony\Component\HttpClient\NativeHttpClient;
|
|
21 | 22 | use Symfony\Component\HttpClient\Retry\GenericRetryStrategy;
|
22 | 23 | use Symfony\Component\HttpClient\RetryableHttpClient;
|
23 | 24 | use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
| 25 | +use Symfony\Contracts\HttpClient\Test\TestHttpServer; |
24 | 26 |
|
25 | 27 | class RetryableHttpClientTest extends TestCase
|
26 | 28 | {
|
@@ -244,4 +246,33 @@ public function testRetryOnErrorAssertContent()
|
244 | 246 | self::assertSame('Test out content', $response->getContent());
|
245 | 247 | self::assertSame('Test out content', $response->getContent(), 'Content should be buffered');
|
246 | 248 | }
|
| 249 | + |
| 250 | + /** |
| 251 | + * @testWith ["GET"] |
| 252 | + * ["POST"] |
| 253 | + * ["PUT"] |
| 254 | + * ["PATCH"] |
| 255 | + * ["DELETE"] |
| 256 | + */ |
| 257 | + public function testRetryOnHeaderTimeout(string $method) |
| 258 | + { |
| 259 | + $client = HttpClient::create(); |
| 260 | + |
| 261 | + if ($client instanceof NativeHttpClient) { |
| 262 | + $this->markTestSkipped('NativeHttpClient cannot timeout before receiving headers'); |
| 263 | + } |
| 264 | + |
| 265 | + TestHttpServer::start(); |
| 266 | + |
| 267 | + $client = new RetryableHttpClient($client); |
| 268 | + $response = $client->request($method, 'http://localhost:8057/timeout-header', ['timeout' => 0.1]); |
| 269 | + |
| 270 | + try { |
| 271 | + $response->getStatusCode(); |
| 272 | + $this->fail(TimeoutException::class.' expected'); |
| 273 | + } catch (TimeoutException $e) { |
| 274 | + } |
| 275 | + |
| 276 | + $this->assertSame('Idle timeout reached for "http://localhost:8057/timeout-header".', $response->getInfo('error')); |
| 277 | + } |
247 | 278 | }
|
0 commit comments