Skip to content

Commit db4b39f

Browse files
[HttpClient] fix monitoring timeouts when other streams are active
1 parent 1bfad45 commit db4b39f

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

Test/HttpClientTestCase.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,30 @@ public function testUncheckedTimeoutThrows()
786786
}
787787
}
788788

789+
public function testTimeoutWithActiveConcurrentStream()
790+
{
791+
$p1 = TestHttpServer::start(8067);
792+
$p2 = TestHttpServer::start(8077);
793+
794+
$client = $this->getHttpClient(__FUNCTION__);
795+
$streamingResponse = $client->request('GET', 'http://localhost:8067/max-duration');
796+
$blockingResponse = $client->request('GET', 'http://localhost:8077/timeout-body', [
797+
'timeout' => 0.25,
798+
]);
799+
800+
$this->assertSame(200, $streamingResponse->getStatusCode());
801+
$this->assertSame(200, $blockingResponse->getStatusCode());
802+
803+
$this->expectException(TransportExceptionInterface::class);
804+
805+
try {
806+
$blockingResponse->getContent();
807+
} finally {
808+
$p1->stop();
809+
$p2->stop();
810+
}
811+
}
812+
789813
public function testDestruct()
790814
{
791815
$client = $this->getHttpClient(__FUNCTION__);

Test/TestHttpServer.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,28 @@
1919
*/
2020
class TestHttpServer
2121
{
22-
private static $process;
22+
private static $process = [];
2323

24-
public static function start()
24+
public static function start(int $port = 8057)
2525
{
26-
if (self::$process) {
27-
self::$process->stop();
26+
if (isset(self::$process[$port])) {
27+
self::$process[$port]->stop();
28+
} else {
29+
register_shutdown_function(static function () use ($port) {
30+
self::$process[$port]->stop();
31+
});
2832
}
2933

3034
$finder = new PhpExecutableFinder();
31-
$process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', '127.0.0.1:8057']));
35+
$process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', '127.0.0.1:'.$port]));
3236
$process->setWorkingDirectory(__DIR__.'/Fixtures/web');
3337
$process->start();
38+
self::$process[$port] = $process;
3439

3540
do {
3641
usleep(50000);
37-
} while (!@fopen('http://127.0.0.1:8057/', 'r'));
42+
} while (!@fopen('http://127.0.0.1:'.$port, 'r'));
3843

39-
self::$process = $process;
44+
return $process;
4045
}
4146
}

0 commit comments

Comments
 (0)