Skip to content

Commit

Permalink
minor #36771 [HttpClient] test that timeout is not fatal (nicolas-gre…
Browse files Browse the repository at this point in the history
…kas)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpClient] test that timeout is not fatal

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Commits
-------

36ccf4c [HttpClient] test that timeout is not fatal
  • Loading branch information
nicolas-grekas committed May 9, 2020
2 parents 3783200 + 36ccf4c commit 99d5818
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php
Expand Up @@ -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
Expand Down Expand Up @@ -91,4 +92,21 @@ public function testNonBlockingStream()
$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());
}
}
Expand Up @@ -132,6 +132,7 @@ protected function getHttpClient(string $testCase): HttpClientInterface

case 'testTimeoutOnStream':
case 'testUncheckedTimeoutThrows':
case 'testTimeoutIsNotAFatalError':
$body = ['<1>', '', '<2>'];
$responses[] = new MockResponse($body, ['response_headers' => $headers]);
break;
Expand Down

0 comments on commit 99d5818

Please sign in to comment.