8000 [HttpClient] test that timeout is not fatal · symfony/symfony@36ccf4c · GitHub
[go: up one dir, main page]

Skip to content

Commit 36ccf4c

Browse files
[HttpClient] test that timeout is not fatal
1 parent 3783200 commit 36ccf4c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Symfony/Component/HttpClient/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\Contracts\HttpClient\Test\HttpClientTestCase as BaseHttpClientTestCase;
1617

1718
abstract class HttpClientTestCase extends BaseHttpClientTestCase
@@ -91,4 +92,21 @@ public function testNonBlockingStream()
9192
$this->assertSame('', fread($stream, 8192));
9293
$this->assertTrue(feof($stream));
9394
}
95+
96+
public function testTimeoutIsNotAFatalError()
97+
{
98+
$client = $this->getHttpClient(__FUNCTION__);
99+
$response = $client->request('GET', 'http://localhost:8057/timeout-body', [
100+
'timeout' => 0.1,
101+
]);
102+
103+
try {
104+
$response->getContent();
105+
$this->fail(TransportException::class.' expected');
106+
} catch (TransportException $e) {
107+
}
108+
109+
usleep(400000);
110+
$this->assertSame('<1><2>', $response->getContent());
111+
}
94112
}

src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php

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

133133
case 'testTimeoutOnStream':
134134
case 'testUncheckedTimeoutThrows':
135+
case 'testTimeoutIsNotAFatalError':
135136
$body = ['<1>', '', '<2>'];
136137
$responses[] = new MockResponse($body, ['response_headers' => $headers]);
137138
break;

0 commit comments

Comments
 (0)
0