Skip to content

Fix #115 - buffer each StreamedResponse chunk when sending data to swoole worker output #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/swoole/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<directory>./tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<coverage>
<include>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>
2 changes: 1 addition & 1 deletion src/swoole/src/SymfonyHttpBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static function reflectSymfonyResponse(SymfonyResponse $sfResponse, Respo
$response->write($buffer);

return '';
});
}, 4096);
$sfResponse->sendContent();
ob_end_clean();
$response->end();
Expand Down
8 changes: 4 additions & 4 deletions src/swoole/tests/Unit/RuntimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RuntimeTest extends TestCase
{
public function testGetRunnerCreatesARunnerForCallbacks(): void
{
$options = [];
$options = ['error_handler' => false];
$runtime = new Runtime($options);

$application = static function (): void {
Expand All @@ -27,7 +27,7 @@ public function testGetRunnerCreatesARunnerForCallbacks(): void

public function testGetRunnerCreatesARunnerForSymfony(): void
{
$options = [];
$options = ['error_handler' => false];
$runtime = new Runtime($options);

$application = $this->createMock(HttpKernelInterface::class);
Expand All @@ -38,7 +38,7 @@ public function testGetRunnerCreatesARunnerForSymfony(): void

public function testGetRunnerCreatesARunnerForLaravel(): void
{
$options = [];
$options = ['error_handler' => false];
$runtime = new Runtime($options);

$application = $this->createMock(Kernel::class);
Expand All @@ -49,7 +49,7 @@ public function testGetRunnerCreatesARunnerForLaravel(): void

public function testGetRunnerFallbacksToClosureRunner(): void
{
$options = [];
$options = ['error_handler' => false];
$runtime = new Runtime($options);

$runner = $runtime->getRunner(null);
Expand Down
19 changes: 19 additions & 0 deletions src/swoole/tests/Unit/SymfonyHttpBridgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,23 @@ public function testThatSymfonyBinaryFileResponseWithRangeIsReflected(): void

SymfonyHttpBridge::reflectSymfonyResponse($sfResponse, $response);
}

public function testStreamedResponseWillRespondWithOneChunkAtATime(): void
{
$sfResponse = new StreamedResponse(static function () {
echo str_repeat('a', 4096);
echo str_repeat('b', 4095);
});

$response = $this->createMock(Response::class);
$response->expects(self::exactly(2))
->method('write')
->with(self::logicalOr(
str_repeat('a', 4096),
str_repeat('b', 4095)
));
$response->expects(self::once())->method('end');

SymfonyHttpBridge::reflectSymfonyResponse($sfResponse, $response);
}
}