Skip to content

Commit

Permalink
Add tests for delayed request handler
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Dec 15, 2024
1 parent f3bf041 commit 4b87c0f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
31 changes: 31 additions & 0 deletions test/Driver/Http1DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1178,4 +1178,35 @@ public function testSwitchingProtocolsUpgrade(): void

self::assertStringStartsWith("HTTP/1.1 101 Switching Protocols\r\n", $output->buffer());
}

public function testTimeoutSuspendedDuringRequestHandler(): void
{
$requestHandler = new ClosureRequestHandler(function (): Response {
delay(2);
return new Response(HttpStatus::ACCEPTED, body: 'Hello World!');
});

$driver = new Http1Driver(
$requestHandler,
$this->createMock(ErrorHandler::class),
new NullLogger,
connectionTimeout: 1,
);

$client = $this->createClientMock();
$client->expects(self::never())
->method('close');

$output = new WritableBuffer();

$driver->handleClient(
$client,
new ReadableBuffer("GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"),
$output,
);

$output->close();

self::assertStringStartsWith('HTTP/1.1 202', $output->buffer());
}
}
41 changes: 40 additions & 1 deletion test/Driver/Http2DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,6 @@ public function testFlowControl(): void
self::markTestSkipped('Not supported with nghttp2, disable ffi for this test.');
}

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

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

public function testTimeoutSuspendedDuringRequestHandler(): void
{
$requestHandler = new ClosureRequestHandler(function (): Response {
delay(2);
return new Response(HttpStatus::ACCEPTED, body: 'Hello World!');
});

$this->driver = new Http2Driver(
$requestHandler,
$this->createMock(ErrorHandler::class),
new NullLogger,
streamTimeout: 1,
connectionTimeout: 1,
);

$headers = [
":authority" => ["localhost:8888"],
":path" => ["/"],
":scheme" => ["https"],
":method" => ["GET"],
];

$input = new Queue();
$this->givenInput(new ReadableIterableStream($input->iterate()));
$frames = $this->whenReceivingFrames();

$input->push(Http2Parser::PREFACE);
$input->push(self::packHeader($headers));

$frames->continue(); // Skip settings frame.

self::assertTrue($frames->continue());
$frame = $frames->getValue();
self::assertSame(Http2Parser::HEADERS, $frame['type']);
self::assertSame(Http2Parser::END_HEADERS, $frame['flags']);
self::assertSame(1, $frame['stream']);

$input->complete();
}

protected function givenPush(string $uri): void
{
$this->pushes[] = $uri;
Expand Down

0 comments on commit 4b87c0f

Please sign in to comment.