Skip to content

Commit 42e5978

Browse files
Merge branch '5.0'
* 5.0: [HttpClient] test that timeout is not fatal
2 parents 7f3c90e + 4d9543a commit 42e5978

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Tests/HttpClientTestCase.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\HttpClient\Tests;
1313

1414
use Symfony\Component\HttpClient\Exception\ClientException;
15+
use Symfony\Component\HttpClient\Exception\TransportException;
1516
use Symfony\Component\HttpClient\Response\StreamWrapper;
1617
use Symfony\Component\Process\Exception\ProcessFailedException;
1718
use Symfony\Component\Process\Process;
@@ -104,6 +105,23 @@ public function testNonBlockingStream()
104105
$this->assertTrue(feof($stream));
105106
}
106107

108+
public function testTimeoutIsNotAFatalError()
109+
{
110+
$client = $this->getHttpClient(__FUNCTION__);
111+
$response = $client->request('GET', 'http://localhost:8057/timeout-body', [
112+
'timeout' => 0.1,
113+
]);
114+
115+
try {
116+
$response->getContent();
117+
$this->fail(TransportException::class.' expected');
118+
} catch (TransportException $e) {
119+
}
120+
121+
usleep(400000);
122+
$this->assertSame('<1><2>', $response->getContent());
123+
}
124+
107125
public function testResponseStreamRewind()
108126
{
109127
$client = $this->getHttpClient(__FUNCTION__);

Tests/MockHttpClientTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ protected function getHttpClient(string $testCase): HttpClientInterface
253253

254254
case 'testTimeoutOnStream':
255255
case 'testUncheckedTimeoutThrows':
256+
case 'testTimeoutIsNotAFatalError':
256257
$body = ['<1>', '', '<2>'];
257258
$responses[] = new MockResponse($body, ['response_headers' => $headers]);
258259
break;

0 commit comments

Comments
 (0)