[HttpClient] test that timeout is not fatal

This commit is contained in:
Nicolas Grekas 2020-05-09 12:17:38 +02:00
parent 3783200074
commit 36ccf4c65b
2 changed files with 19 additions and 0 deletions

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\HttpClient\Tests;
use Symfony\Component\HttpClient\Exception\ClientException;
use Symfony\Component\HttpClient\Exception\TransportException;
use Symfony\Contracts\HttpClient\Test\HttpClientTestCase as BaseHttpClientTestCase;
abstract class HttpClientTestCase extends BaseHttpClientTestCase
@ -91,4 +92,21 @@ abstract class HttpClientTestCase extends BaseHttpClientTestCase
$this->assertSame('', fread($stream, 8192));
$this->assertTrue(feof($stream));
}
public function testTimeoutIsNotAFatalError()
{
$client = $this->getHttpClient(__FUNCTION__);
$response = $client->request('GET', 'http://localhost:8057/timeout-body', [
'timeout' => 0.1,
]);
try {
$response->getContent();
$this->fail(TransportException::class.' expected');
} catch (TransportException $e) {
}
usleep(400000);
$this->assertSame('<1><2>', $response->getContent());
}
}

View File

@ -132,6 +132,7 @@ class MockHttpClientTest extends HttpClientTestCase
case 'testTimeoutOnStream':
case 'testUncheckedTimeoutThrows':
case 'testTimeoutIsNotAFatalError':
$body = ['<1>', '', '<2>'];
$responses[] = new MockResponse($body, ['response_headers' => $headers]);
break;