From b3a7bd491ac00652aabd4179b9815d3abddb5414 Mon Sep 17 00:00:00 2001 From: k911 Date: Mon, 10 May 2021 21:03:45 +0200 Subject: [PATCH] debugging part 2 --- Dockerfile | 2 +- docker-compose.yml | 2 +- .../DebugHttpKernelRequestHandler.php | 34 +++++++++---------- .../ExceptionHandler/JsonExceptionHandler.php | 5 +++ .../SwooleServerStaticFilesServingTest.php | 3 +- tests/Feature/SymfonyProfilerTest.php | 8 +++-- .../CodeCoverageRequestHandler.php | 1 - .../Symfony/app/config/profiler/swoole.yaml | 4 +++ 8 files changed, 36 insertions(+), 23 deletions(-) create mode 100644 tests/Fixtures/Symfony/app/config/profiler/swoole.yaml diff --git a/Dockerfile b/Dockerfile index f4ba5349..2ae52ec1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ RUN pecl install xdebug && \ FROM ext-builder as ext-swoole RUN apk add --no-cache git -ARG SWOOLE_VERSION="4.5.11" +ARG SWOOLE_VERSION="4.6.5" RUN if $(echo "$SWOOLE_VERSION" | grep -qE '^[4-9]\.[0-9]+\.[0-9]+$'); then SWOOLE_GIT_REF="v$SWOOLE_VERSION"; else SWOOLE_GIT_REF="$SWOOLE_VERSION"; fi && \ git clone https://github.com/swoole/swoole-src.git --branch "$SWOOLE_GIT_REF" --depth 1 && \ cd swoole-src && \ diff --git a/docker-compose.yml b/docker-compose.yml index 96fc0caf..04346426 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ x-env-aliases: PHP_TAG: "${PHP_VERSION:-7.4}-cli-alpine${ALPINE_VERSION:-3.13}" PHP_API_VERSION: "${PHP_API_VERSION:-20190902}" COMPOSER_ARGS: "${COMPOSER_ARGS:-install}" - SWOOLE_VERSION: "${SWOOLE_VERSION:-4.5.11}" + SWOOLE_VERSION: "${SWOOLE_VERSION:-4.6.5}" COMPOSER_TAG: "${COMPOSER_TAG:-2.0.11}" volumes: diff --git a/src/Bridge/Symfony/HttpKernel/DebugHttpKernelRequestHandler.php b/src/Bridge/Symfony/HttpKernel/DebugHttpKernelRequestHandler.php index e9342b91..bdd37652 100644 --- a/src/Bridge/Symfony/HttpKernel/DebugHttpKernelRequestHandler.php +++ b/src/Bridge/Symfony/HttpKernel/DebugHttpKernelRequestHandler.php @@ -31,25 +31,25 @@ public function __construct(RequestHandlerInterface $decorated, KernelInterface */ public function handle(Request $request, Response $response): void { - if ($this->kernel->isDebug()) { - replace_object_property($this->kernel, 'startTime', \microtime(true)); - } +// if ($this->kernel->isDebug()) { +// replace_object_property($this->kernel, 'startTime', \microtime(true)); +// } $this->decorated->handle($request, $response); - if ($this->kernel->isDebug()) { - if ($this->container->has('debug.stopwatch')) { - /** @var Stopwatch $stopwatch */ - $stopwatch = $this->container->get('debug.stopwatch'); - $stopwatch->reset(); - } - - if ($this->container->has('profiler')) { - /** @var Profiler $profiler */ - $profiler = $this->container->get('profiler'); - $profiler->reset(); - $profiler->enable(); - } - } +// if ($this->kernel->isDebug()) { +// if ($this->container->has('debug.stopwatch')) { +// /** @var Stopwatch $stopwatch */ +// $stopwatch = $this->container->get('debug.stopwatch'); +// $stopwatch->reset(); +// } +// +// if ($this->container->has('profiler')) { +// /** @var Profiler $profiler */ +// $profiler = $this->container->get('profiler'); +// $profiler->reset(); +// $profiler->enable(); +// } +// } } } diff --git a/src/Server/RequestHandler/ExceptionHandler/JsonExceptionHandler.php b/src/Server/RequestHandler/ExceptionHandler/JsonExceptionHandler.php index 0ba70279..0b957321 100644 --- a/src/Server/RequestHandler/ExceptionHandler/JsonExceptionHandler.php +++ b/src/Server/RequestHandler/ExceptionHandler/JsonExceptionHandler.php @@ -25,6 +25,11 @@ public function handle(Request $request, Throwable $exception, Response $respons { $data = $this->exceptionArrayTransformer->transform($exception, $this->verbosity); + if (\method_exists($response, 'isWritable') && !$response->isWritable()) { + echo 'Response is not writable'.\PHP_EOL; + + return; + } $response->header(Http::HEADER_CONTENT_TYPE, Http::CONTENT_TYPE_APPLICATION_JSON); $response->status(500); $response->end(\json_encode($data, \JSON_THROW_ON_ERROR)); diff --git a/tests/Feature/SwooleServerStaticFilesServingTest.php b/tests/Feature/SwooleServerStaticFilesServingTest.php index 3cee99a1..b1c8a547 100644 --- a/tests/Feature/SwooleServerStaticFilesServingTest.php +++ b/tests/Feature/SwooleServerStaticFilesServingTest.php @@ -22,12 +22,13 @@ public function testAdvancedStaticFilesServerWithAutoRegistration(): void '--port=9999', ], ['APP_ENV' => 'auto']); - $serverRun->setTimeout(10); + $serverRun->setTimeout(self::coverageEnabled() ? 10 : 5); $serverRun->start(); $this->runAsCoroutineAndWait(function (): void { $client = HttpClient::fromDomain('localhost', 9999, false); $this->assertTrue($client->connect()); + $this->assertHelloWorldRequestSucceeded($client); $response = $client->send('/robots.txt')['response']; diff --git a/tests/Feature/SymfonyProfilerTest.php b/tests/Feature/SymfonyProfilerTest.php index a61f2658..a6a186ee 100644 --- a/tests/Feature/SymfonyProfilerTest.php +++ b/tests/Feature/SymfonyProfilerTest.php @@ -6,6 +6,7 @@ use K911\Swoole\Client\HttpClient; use K911\Swoole\Tests\Fixtures\Symfony\TestBundle\Test\ServerTestCase; +use Swoole\Coroutine; final class SymfonyProfilerTest extends ServerTestCase { @@ -16,7 +17,7 @@ protected function setUp(): void $this->markTestSkippedIfXdebugEnabled(); } - public function testAdvancedStaticFilesServerWithAutoRegistration(): void + public function testSymfonyProfilerTwigDebugLink(): void { $serverRun = $this->createConsoleProcess([ 'swoole:server:run', @@ -24,12 +25,13 @@ public function testAdvancedStaticFilesServerWithAutoRegistration(): void '--port=9999', ], ['APP_ENV' => 'profiler']); - $serverRun->setTimeout(10); + $serverRun->setTimeout(self::coverageEnabled() ? 10 : 5); $serverRun->start(); $this->runAsCoroutineAndWait(function (): void { $client = HttpClient::fromDomain('localhost', 9999, false); $this->assertTrue($client->connect()); + $this->assertHelloWorldRequestSucceeded($client); $response = $client->send('/twig')['response']; @@ -37,6 +39,8 @@ public function testAdvancedStaticFilesServerWithAutoRegistration(): void $this->assertNotEmpty($response['headers']['x-debug-token']); $debugToken = $response['headers']['x-debug-token']; + Coroutine::sleep(2); + $client2 = HttpClient::fromDomain('localhost', 9999, false); $this->assertTrue($client2->connect()); diff --git a/tests/Fixtures/Symfony/CoverageBundle/RequestHandler/CodeCoverageRequestHandler.php b/tests/Fixtures/Symfony/CoverageBundle/RequestHandler/CodeCoverageRequestHandler.php index 95206f36..d08cb4ad 100644 --- a/tests/Fixtures/Symfony/CoverageBundle/RequestHandler/CodeCoverageRequestHandler.php +++ b/tests/Fixtures/Symfony/CoverageBundle/RequestHandler/CodeCoverageRequestHandler.php @@ -4,7 +4,6 @@ namespace K911\Swoole\Tests\Fixtures\Symfony\CoverageBundle\RequestHandler; -use function K911\Swoole\get_object_property; use K911\Swoole\Server\RequestHandler\RequestHandlerInterface; use K911\Swoole\Tests\Fixtures\Symfony\CoverageBundle\Coverage\CodeCoverageManager; use Swoole\Http\Request; diff --git a/tests/Fixtures/Symfony/app/config/profiler/swoole.yaml b/tests/Fixtures/Symfony/app/config/profiler/swoole.yaml new file mode 100644 index 00000000..05eaebad --- /dev/null +++ b/tests/Fixtures/Symfony/app/config/profiler/swoole.yaml @@ -0,0 +1,4 @@ +swoole: + http_server: + exception_handler: + type: symfony