Skip to content

Commit 317747c

Browse files
[HttpClient] Fix handling timeouts when responses are destructed
1 parent 1bef9a4 commit 317747c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

HttpClient/Test/HttpClientTestCase.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,38 @@ public function testTimeoutWithActiveConcurrentStream()
810810
}
811811
}
812812

813+
public function testTimeoutOnDestruct()
814+
{
815+
$p1 = TestHttpServer::start(8067);
816+
$p2 = TestHttpServer::start(8077);
817+
818+
$client = $this->getHttpClient(__FUNCTION__);
819+
$start = microtime(true);
820+
$responses = [];
821+
822+
$responses[] = $client->request('GET', 'http://localhost:8067/timeout-header', ['timeout' => 0.25]);
823+
$responses[] = $client->request('GET', 'http://localhost:8077/timeout-header', ['timeout' => 0.25]);
824+
$responses[] = $client->request('GET', 'http://localhost:8067/timeout-header', ['timeout' => 0.25]);
825+
$responses[] = $client->request('GET', 'http://localhost:8077/timeout-header', ['timeout' => 0.25]);
826+
827+
try {
828+
while ($response = array_shift($responses)) {
829+
try {
830+
unset($response);
831+
$this->fail(TransportExceptionInterface::class.' expected');
832+
} catch (TransportExceptionInterface $e) {
833+
}
834+
}
835+
836+
$duration = microtime(true) - $start;
837+
838+
$this->assertLessThan(1.0, $duration);
839+
} finally {
840+
$p1->stop();
841+
$p2->stop();
842+
}
843+
}
844+
813845
public function testDestruct()
814846
{
815847
$client = $this->getHttpClient(__FUNCTION__);

0 commit comments

Comments
 (0)