[HttpClient] test that timeout is not fatal
This commit is contained in:
parent
3783200074
commit
36ccf4c65b
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\HttpClient\Tests;
|
namespace Symfony\Component\HttpClient\Tests;
|
||||||
|
|
||||||
use Symfony\Component\HttpClient\Exception\ClientException;
|
use Symfony\Component\HttpClient\Exception\ClientException;
|
||||||
|
use Symfony\Component\HttpClient\Exception\TransportException;
|
||||||
use Symfony\Contracts\HttpClient\Test\HttpClientTestCase as BaseHttpClientTestCase;
|
use Symfony\Contracts\HttpClient\Test\HttpClientTestCase as BaseHttpClientTestCase;
|
||||||
|
|
||||||
abstract class HttpClientTestCase extends BaseHttpClientTestCase
|
abstract class HttpClientTestCase extends BaseHttpClientTestCase
|
||||||
@ -91,4 +92,21 @@ abstract class HttpClientTestCase extends BaseHttpClientTestCase
|
|||||||
$this->assertSame('', fread($stream, 8192));
|
$this->assertSame('', fread($stream, 8192));
|
||||||
$this->assertTrue(feof($stream));
|
$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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,6 +132,7 @@ class MockHttpClientTest extends HttpClientTestCase
|
|||||||
|
|
||||||
case 'testTimeoutOnStream':
|
case 'testTimeoutOnStream':
|
||||||
case 'testUncheckedTimeoutThrows':
|
case 'testUncheckedTimeoutThrows':
|
||||||
|
case 'testTimeoutIsNotAFatalError':
|
||||||
$body = ['<1>', '', '<2>'];
|
$body = ['<1>', '', '<2>'];
|
||||||
$responses[] = new MockResponse($body, ['response_headers' => $headers]);
|
$responses[] = new MockResponse($body, ['response_headers' => $headers]);
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user