Skip to content

Commit e3ba268

Browse files
[HttpClient] add TimeoutExceptionInterface
1 parent 88cb256 commit e3ba268

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Contracts\HttpClient\Exception;
13+
14+
/**
15+
* When an idle timeout occurs.
16+
*
17+
* @author Nicolas Grekas <[email protected]>
18+
*/
19+
interface TimeoutExceptionInterface extends TransportExceptionInterface
20+
{
21+
}

Test/Fixtures/web/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
echo '<1>';
117117
@ob_flush();
118118
flush();
119-
usleep(500000);
119+
usleep(600000);
120120
echo '<2>';
121121
exit;
122122

Test/HttpClientTestCase.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
1616
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
17+
use Symfony\Contracts\HttpClient\Exception\TimeoutExceptionInterface;
1718
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
1819
use Symfony\Contracts\HttpClient\HttpClientInterface;
1920

@@ -739,9 +740,35 @@ public function testTimeoutOnAccess()
739740
$response->getHeaders();
740741
}
741742

742-
public function testTimeoutOnStream()
743+
public function testTimeoutIsNotAFatalError()
743744
{
744745
usleep(300000); // wait for the previous test to release the server
746+
$client = $this->getHttpClient(__FUNCTION__);
747+
$response = $client->request('GET', 'http://localhost:8057/timeout-body', [
748+
'timeout' => 0.3,
749+
]);
750+
751+
try {
752+
$response->getContent();
753+
$this->fail(TimeoutExceptionInterface::class.' expected');
754+
} catch (TimeoutExceptionInterface $e) {
755+
}
756+
757+
for ($i = 0; $i < 10; ++$i) {
758+
try {
759+
$this->assertSame('<1><2>', $response->getContent());
760+
break;
761+
} catch (TimeoutExceptionInterface $e) {
762+
}
763+
}
764+
765+
if (10 === $i) {
766+
throw $e;
767+
}
768+
}
769+
770+
public function testTimeoutOnStream()
771+
{
745772
$client = $this->getHttpClient(__FUNCTION__);
746773
$response = $client->request('GET', 'http://localhost:8057/timeout-body');
747774

0 commit comments

Comments
 (0)