Skip to content

Commit 4b87c0f

Browse files
committed
Add tests for delayed request handler
1 parent f3bf041 commit 4b87c0f

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

test/Driver/Http1DriverTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,4 +1178,35 @@ public function testSwitchingProtocolsUpgrade(): void
11781178

11791179
self::assertStringStartsWith("HTTP/1.1 101 Switching Protocols\r\n", $output->buffer());
11801180
}
1181+
1182+
public function testTimeoutSuspendedDuringRequestHandler(): void
1183+
{
1184+
$requestHandler = new ClosureRequestHandler(function (): Response {
1185+
delay(2);
1186+
return new Response(HttpStatus::ACCEPTED, body: 'Hello World!');
1187+
});
1188+
1189+
$driver = new Http1Driver(
1190+
$requestHandler,
1191+
$this->createMock(ErrorHandler::class),
1192+
new NullLogger,
1193+
connectionTimeout: 1,
1194+
);
1195+
1196+
$client = $this->createClientMock();
1197+
$client->expects(self::never())
1198+
->method('close');
1199+
1200+
$output = new WritableBuffer();
1201+
1202+
$driver->handleClient(
1203+
$client,
1204+
new ReadableBuffer("GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"),
1205+
$output,
1206+
);
1207+
1208+
$output->close();
1209+
1210+
self::assertStringStartsWith('HTTP/1.1 202', $output->buffer());
1211+
}
11811212
}

test/Driver/Http2DriverTest.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,6 @@ public function testFlowControl(): void
521521
self::markTestSkipped('Not supported with nghttp2, disable ffi for this test.');
522522
}
523523

524-
$this->initDriver();
525524
$request = async(fn () => $this->whenRequestIsReceived());
526525

527526
$input = new Queue;
@@ -868,6 +867,46 @@ public function testSendingLargeHeaders(): void
868867
self::assertSame($value, $request->getHeader($header));
869868
}
870869

870+
public function testTimeoutSuspendedDuringRequestHandler(): void
871+
{
872+
$requestHandler = new ClosureRequestHandler(function (): Response {
873+
delay(2);
874+
return new Response(HttpStatus::ACCEPTED, body: 'Hello World!');
875+
});
876+
877+
$this->driver = new Http2Driver(
878+
$requestHandler,
879+
$this->createMock(ErrorHandler::class),
880+
new NullLogger,
881+
streamTimeout: 1,
882+
connectionTimeout: 1,
883+
);
884+
885+
$headers = [
886+
":authority" => ["localhost:8888"],
887+
":path" => ["/"],
888+
":scheme" => ["https"],
889+
":method" => ["GET"],
890+
];
891+
892+
$input = new Queue();
893+
$this->givenInput(new ReadableIterableStream($input->iterate()));
894+
$frames = $this->whenReceivingFrames();
895+
896+
$input->push(Http2Parser::PREFACE);
897+
$input->push(self::packHeader($headers));
898+
899+
$frames->continue(); // Skip settings frame.
900+
901+
self::assertTrue($frames->continue());
902+
$frame = $frames->getValue();
903+
self::assertSame(Http2Parser::HEADERS, $frame['type']);
904+
self::assertSame(Http2Parser::END_HEADERS, $frame['flags']);
905+
self::assertSame(1, $frame['stream']);
906+
907+
$input->complete();
908+
}
909+
871910
protected function givenPush(string $uri): void
872911
{
873912
$this->pushes[] = $uri;

0 commit comments

Comments
 (0)