diff --git a/.github/workflows/quality.yaml b/.github/workflows/quality.yaml deleted file mode 100644 index 96363f7..0000000 --- a/.github/workflows/quality.yaml +++ /dev/null @@ -1,68 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: Quality - -on: - push: - branches: [ "2.x", "issue_17_failed_message_never_retried" ] - pull_request: - branches: [ "2.x" ] - -permissions: - contents: read - -jobs: - symfony-tests: - strategy: - fail-fast: false - matrix: - php: ['8.0', '8.1', '8.2', '8.3'] - runs-on: ubuntu-latest - - services: - mariadb: - image: mariadb:10.11 - ports: - - 3306:3306 - env: - MYSQL_USER: user - MYSQL_PASSWORD: nopassword - MYSQL_DATABASE: app_test - MYSQL_ROOT_PASSWORD: nopassword - options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 - - - env: - DATABASE_URL: mysql://root:nopassword@127.0.0.1:3306/app?serverVersion=mariadb-10.11.2&charset=utf8mb4 - APP_ENV: test - steps: - # To automatically get bug fixes and new Php versions for shivammathur/setup-php, - # change this to (see https://github.com/shivammathur/setup-php#bookmark-versioning): - # uses: shivammathur/setup-php@v2 - - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - coverage: xdebug - - - uses: actions/checkout@v4 -# - name: Copy .env.test.local -# run: php -r "file_exists('.env.test.local') || copy('.env.test', '.env.test.local');" - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v4 - with: - path: vendor - key: ${{ runner.os }}-php${{ matrix.php }}-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php${{ matrix.php }}- - - name: Install Dependencies - run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - - name: Create Database - run: | - cd tests/Application - bin/console doctrine:migration:migrate -n - - name: Execute tests (Unit and Feature tests) via PHPUnit - run: vendor/bin/phpunit --process-isolation diff --git a/composer.json b/composer.json index 9208386..42e9dc9 100644 --- a/composer.json +++ b/composer.json @@ -41,12 +41,10 @@ "symfony/dotenv": "^5.4|^6.0", "symfony/runtime": "^5.4|^6.0", "symfony/messenger": "^5.4|^6.0", - "symfony/doctrine-messenger": "^5.4|^6.0", "symfony/monolog-bundle": "^3.10", "doctrine/doctrine-bundle": "^2.12", "doctrine/doctrine-migrations-bundle": "^3.3", - "doctrine/orm": "^2.19", - "phpunit/phpunit": "^9.6" + "doctrine/orm": "^2.19" }, "suggest": { "ext-win32service": "On Windows only, install this extension to run PHP Service on Windows Service Manager" diff --git a/lib/DependencyInjection/MessengerPass.php b/lib/DependencyInjection/MessengerPass.php index 4690ce4..38f08d1 100644 --- a/lib/DependencyInjection/MessengerPass.php +++ b/lib/DependencyInjection/MessengerPass.php @@ -8,8 +8,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException; use Symfony\Component\DependencyInjection\Reference; -use Win32ServiceBundle\MessengerSubscriber\SendFailedMessageForRetryListener; -use Win32ServiceBundle\MessengerSubscriber\SendFailedMessageToFailureTransportListener; final class MessengerPass implements CompilerPassInterface { @@ -18,13 +16,6 @@ final class MessengerPass implements CompilerPassInterface private string $win32ServiceRunnerTag = TagRunnerCompilerPass::WIN32SERVICE_RUNNER_TAG.'.messenger'; public function process(ContainerBuilder $container): void - { - $this->processService($container); - $this->processRetryConfig($container); - $this->processFailledConfig($container); - } - - private function processService(ContainerBuilder $container): void { $busIds = []; foreach ($container->findTaggedServiceIds($this->busTag) as $busId => $tags) { @@ -60,34 +51,4 @@ private function processService(ContainerBuilder $container): void } } } - - private function processFailledConfig(ContainerBuilder $container): void - { - if ( - $container->hasDefinition('messenger.failure.send_failed_message_to_failure_transport_listener') === false - || $container->hasDefinition(SendFailedMessageToFailureTransportListener::class) === false - ) { - return; - } - - $serviceSF = $container->findDefinition('messenger.failure.send_failed_message_to_failure_transport_listener'); - - $serviceWin32 = $container->findDefinition(SendFailedMessageToFailureTransportListener::class); - $serviceWin32->replaceArgument('$failureSenders', $serviceSF->getArgument(0)); - } - - private function processRetryConfig(ContainerBuilder $container): void - { - if ( - $container->hasDefinition('messenger.retry.send_failed_message_for_retry_listener') === false - || $container->hasDefinition(SendFailedMessageForRetryListener::class) === false - ) { - return; - } - - $serviceSF = $container->findDefinition('messenger.retry.send_failed_message_for_retry_listener'); - - $serviceWin32 = $container->findDefinition(SendFailedMessageForRetryListener::class); - $serviceWin32->replaceArgument('$sendersLocator', $serviceSF->getArgument(0)); - } } diff --git a/lib/Event/MessengerWorkerStoppedEvent.php b/lib/Event/MessengerWorkerStoppedEvent.php deleted file mode 100644 index 41ac15d..0000000 --- a/lib/Event/MessengerWorkerStoppedEvent.php +++ /dev/null @@ -1,22 +0,0 @@ -messengerServiceRunner = $messengerServiceRunner; - } - - public function getMessengerServiceRunner(): MessengerServiceRunner - { - return $this->messengerServiceRunner; - } -} diff --git a/lib/MessengerSubscriber/AddErrorDetailsStampListener.php b/lib/MessengerSubscriber/AddErrorDetailsStampListener.php deleted file mode 100644 index 46eb0b6..0000000 --- a/lib/MessengerSubscriber/AddErrorDetailsStampListener.php +++ /dev/null @@ -1,31 +0,0 @@ -getThrowable()); - $previousStamp = $event->getEnvelope()->last(ErrorDetailsStamp::class); - - // Do not append duplicate information - if ($previousStamp === null || !$previousStamp->equals($stamp)) { - $event->addStamps($stamp); - } - } - - public static function getSubscribedEvents(): array - { - return [ - // must have higher priority than SendFailedMessageForRetryListener - MessengerWorkerMessageFailedEvent::class => ['onMessageFailed', 200], - ]; - } -} diff --git a/lib/MessengerSubscriber/ResetServicesListener.php b/lib/MessengerSubscriber/ResetServicesListener.php deleted file mode 100644 index 32e9190..0000000 --- a/lib/MessengerSubscriber/ResetServicesListener.php +++ /dev/null @@ -1,43 +0,0 @@ - - */ -class ResetServicesListener implements EventSubscriberInterface -{ - private ServicesResetter $servicesResetter; - - public function __construct(ServicesResetter $servicesResetter) - { - $this->servicesResetter = $servicesResetter; - } - - public function resetServices(MessengerWorkerRunningEvent $event): void - { - if (!$event->isWorkerIdle()) { - $this->servicesResetter->reset(); - } - } - - public function resetServicesAtStop(MessengerWorkerStoppedEvent $event): void - { - $this->servicesResetter->reset(); - } - - public static function getSubscribedEvents(): array - { - return [ - MessengerWorkerRunningEvent::class => ['resetServices', -1024], - MessengerWorkerStoppedEvent::class => ['resetServicesAtStop', -1024], - ]; - } -} diff --git a/lib/MessengerSubscriber/SendFailedMessageForRetryListener.php b/lib/MessengerSubscriber/SendFailedMessageForRetryListener.php deleted file mode 100644 index bdbf687..0000000 --- a/lib/MessengerSubscriber/SendFailedMessageForRetryListener.php +++ /dev/null @@ -1,163 +0,0 @@ -sendersLocator = $sendersLocator; - $this->retryStrategyLocator = $retryStrategyLocator; - $this->logger = $logger; - $this->eventDispatcher = $eventDispatcher; - $this->historySize = $historySize; - } - - public function onMessageFailed(MessengerWorkerMessageFailedEvent $event): void - { - $retryStrategy = $this->getRetryStrategyForTransport($event->getReceiverName()); - $envelope = $event->getEnvelope(); - $throwable = $event->getThrowable(); - - $message = $envelope->getMessage(); - $context = [ - 'class' => $message::class, - ]; - - $shouldRetry = $retryStrategy && $this->shouldRetry($throwable, $envelope, $retryStrategy); - - $retryCount = RedeliveryStamp::getRetryCountFromEnvelope($envelope); - if ($shouldRetry) { - $event->setForRetry(); - - ++$retryCount; - - $delay = $retryStrategy->getWaitingTime($envelope, $throwable); - - if ($this->logger !== null) { - $this->logger->warning('Error thrown while handling message {class}. Sending for retry #{retryCount} using {delay} ms delay. Error: "{error}"', $context + ['retryCount' => $retryCount, 'delay' => $delay, 'error' => $throwable->getMessage(), 'exception' => $throwable]); - } - - // add the delay and retry stamp info - $retryEnvelope = $this->withLimitedHistory($envelope, new DelayStamp($delay), new RedeliveryStamp($retryCount)); - - // re-send the message for retry - $this->getSenderForTransport($event->getReceiverName())->send($retryEnvelope); - - if ($this->eventDispatcher !== null) { - $this->eventDispatcher->dispatch(new WorkerMessageRetriedEvent($retryEnvelope, $event->getReceiverName())); - } - } else { - if ($this->logger !== null) { - $this->logger->critical('Error thrown while handling message {class}. Removing from transport after {retryCount} retries. Error: "{error}"', $context + ['retryCount' => $retryCount, 'error' => $throwable->getMessage(), 'exception' => $throwable]); - } - } - } - - public static function getSubscribedEvents(): array - { - return [ - // must have higher priority than SendFailedMessageToFailureTransportListener - MessengerWorkerMessageFailedEvent::class => ['onMessageFailed', 100], - ]; - } - - /** - * Adds stamps to the envelope by keeping only the First + Last N stamps. - */ - private function withLimitedHistory(Envelope $envelope, StampInterface ...$stamps): Envelope - { - foreach ($stamps as $stamp) { - $history = $envelope->all($stamp::class); - if (\count($history) < $this->historySize) { - $envelope = $envelope->with($stamp); - continue; - } - - $history = array_merge( - [$history[0]], - \array_slice($history, -$this->historySize + 2), - [$stamp] - ); - - $envelope = $envelope->withoutAll($stamp::class)->with(...$history); - } - - return $envelope; - } - - private function shouldRetry(\Throwable $e, Envelope $envelope, RetryStrategyInterface $retryStrategy): bool - { - if ($e instanceof RecoverableExceptionInterface) { - return true; - } - - // if one or more nested Exceptions is an instance of RecoverableExceptionInterface we should retry - // if ALL nested Exceptions are an instance of UnrecoverableExceptionInterface we should not retry - if ($e instanceof HandlerFailedException) { - $shouldNotRetry = true; - foreach ($e->getNestedExceptions() as $nestedException) { - if ($nestedException instanceof RecoverableExceptionInterface) { - return true; - } - - if (!$nestedException instanceof UnrecoverableExceptionInterface) { - $shouldNotRetry = false; - break; - } - } - if ($shouldNotRetry) { - return false; - } - } - - if ($e instanceof UnrecoverableExceptionInterface) { - return false; - } - - return $retryStrategy->isRetryable($envelope, $e); - } - - private function getRetryStrategyForTransport(string $alias): ?RetryStrategyInterface - { - if ($this->retryStrategyLocator->has($alias)) { - return $this->retryStrategyLocator->get($alias); - } - - return null; - } - - private function getSenderForTransport(string $alias): SenderInterface - { - if ($this->sendersLocator->has($alias)) { - return $this->sendersLocator->get($alias); - } - - throw new RuntimeException(\sprintf('Could not find sender "%s" based on the same receiver to send the failed message to for retry.', $alias)); - } -} diff --git a/lib/MessengerSubscriber/SendFailedMessageToFailureTransportListener.php b/lib/MessengerSubscriber/SendFailedMessageToFailureTransportListener.php deleted file mode 100644 index ca8cb23..0000000 --- a/lib/MessengerSubscriber/SendFailedMessageToFailureTransportListener.php +++ /dev/null @@ -1,70 +0,0 @@ -failureSenders = $failureSenders; - $this->logger = $logger; - } - - public function onMessageFailed(MessengerWorkerMessageFailedEvent $event): void - { - if ($event->willRetry()) { - return; - } - - if (!$this->failureSenders->has($event->getReceiverName())) { - return; - } - - $failureSender = $this->failureSenders->get($event->getReceiverName()); - if ($failureSender === null) { - return; - } - - $envelope = $event->getEnvelope(); - - // avoid re-sending to the failed sender - if ($envelope->last(SentToFailureTransportStamp::class) !== null) { - return; - } - - $envelope = $envelope->with( - new SentToFailureTransportStamp($event->getReceiverName()), - new DelayStamp(0), - new RedeliveryStamp(0) - ); - - if ($this->logger !== null) { - $this->logger->info('Rejected message {class} will be sent to the failure transport {transport}.', [ - 'class' => \get_class($envelope->getMessage()), - 'transport' => $failureSender::class, - ]); - } - - $failureSender->send($envelope); - } - - public static function getSubscribedEvents(): array - { - return [ - MessengerWorkerMessageFailedEvent::class => ['onMessageFailed', -100], - ]; - } -} diff --git a/lib/Model/MessengerServiceRunner.php b/lib/Model/MessengerServiceRunner.php index 78a4029..a512cbe 100644 --- a/lib/Model/MessengerServiceRunner.php +++ b/lib/Model/MessengerServiceRunner.php @@ -26,7 +26,6 @@ use Win32ServiceBundle\Event\MessengerWorkerMessageHandledEvent; use Win32ServiceBundle\Event\MessengerWorkerRunningEvent; use Win32ServiceBundle\Event\MessengerWorkerStartedEvent; -use Win32ServiceBundle\Event\MessengerWorkerStoppedEvent; use Win32ServiceBundle\MessengerSubscriber\StopWorkerOnFailureLimitListener; use Win32ServiceBundle\MessengerSubscriber\StopWorkerOnMemoryLimitListener; use Win32ServiceBundle\MessengerSubscriber\StopWorkerOnMessageLimitListener; @@ -153,8 +152,6 @@ protected function run(int $control): void usleep($sleep); } } - - $this->eventDispatcher->dispatch(new MessengerWorkerStoppedEvent($this)); } protected function lastRunIsTooSlow(float $duration): void diff --git a/lib/Resources/config/services.yaml b/lib/Resources/config/services.yaml index 204a04d..53c0b33 100644 --- a/lib/Resources/config/services.yaml +++ b/lib/Resources/config/services.yaml @@ -12,22 +12,3 @@ services: arguments: - '%win32service.config%' - '%kernel.environment%' - - - Win32ServiceBundle\MessengerSubscriber\SendFailedMessageForRetryListener: - arguments: - $retryStrategyLocator: '@messenger.retry_strategy_locator' - $logger: '@logger' - $eventDispatcher: '@event_dispatcher' - tags: - - { name: 'monolog.logger', channel: 'messenger' } - - Win32ServiceBundle\MessengerSubscriber\SendFailedMessageToFailureTransportListener: - arguments: - $logger: '@logger' - tags: - - {name: 'monolog.logger', channel: 'messenger'} - - Win32ServiceBundle\MessengerSubscriber\ResetServicesListener: - arguments: - - '@services_resetter' diff --git a/lib/Win32ServiceBundle.php b/lib/Win32ServiceBundle.php index 98c8f44..d8825c0 100644 --- a/lib/Win32ServiceBundle.php +++ b/lib/Win32ServiceBundle.php @@ -16,7 +16,7 @@ class Win32ServiceBundle extends Bundle { - public function build(ContainerBuilder $container): void + public function build(ContainerBuilder $container) { $autoconfig = $container->registerForAutoconfiguration(RunnerServiceInterface::class); $autoconfig->addTag(TagRunnerCompilerPass::WIN32SERVICE_RUNNER_TAG); diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index 7783768..0000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,25 +0,0 @@ - - - - - lib - - - - tests/Unit - - - - - - - - - diff --git a/tests/Application/.env.test b/tests/Application/.env.test deleted file mode 100644 index e86db96..0000000 --- a/tests/Application/.env.test +++ /dev/null @@ -1,2 +0,0 @@ - -DATABASE_URL="mysql://root:nopassword@127.0.0.1:3306/app?serverVersion=mariadb-10.11.2&charset=utf8mb4" diff --git a/tests/Application/config/packages/messenger.yaml b/tests/Application/config/packages/messenger.yaml index 4b9c3cd..b0864c7 100644 --- a/tests/Application/config/packages/messenger.yaml +++ b/tests/Application/config/packages/messenger.yaml @@ -16,6 +16,3 @@ framework: # Route your messages to the transports # 'App\Message\YourMessage': async 'Win32ServiceBundle\Tests\Application\Event\TestMessage': async - 'Win32ServiceBundle\Tests\Application\Event\TestRetryMessage': async - 'Win32ServiceBundle\Tests\Application\Event\TestMemoryLimitMessage': async - 'Win32ServiceBundle\Tests\Application\Event\TestTimeLimitMessage': async diff --git a/tests/Application/config/packages/win32service.yaml b/tests/Application/config/packages/win32service.yaml index 9c76325..200d8e1 100644 --- a/tests/Application/config/packages/win32service.yaml +++ b/tests/Application/config/packages/win32service.yaml @@ -6,6 +6,5 @@ win32_service: limit: 10 displayed_name: Demo Messenger Consumer Async %d thread_count: 2 - memory_limit: 128M - time_limit: 1 + memory_limit: 3600 diff --git a/tests/Application/src/Event/TestMemoryLimitMessage.php b/tests/Application/src/Event/TestMemoryLimitMessage.php deleted file mode 100644 index c175176..0000000 --- a/tests/Application/src/Event/TestMemoryLimitMessage.php +++ /dev/null @@ -1,12 +0,0 @@ -logger->info('Memory Limit Message : '.$message->size); - $this->buffer = str_repeat('-*+45defse', (int) ($message->size / 10)); - } -} diff --git a/tests/Application/src/Handler/RetryMessageHandler.php b/tests/Application/src/Handler/RetryMessageHandler.php deleted file mode 100644 index 381b092..0000000 --- a/tests/Application/src/Handler/RetryMessageHandler.php +++ /dev/null @@ -1,24 +0,0 @@ -logger->info('Retry Message'); - throw new RecoverableMessageHandlingException('Retry Message'); - } -} diff --git a/tests/Application/src/Handler/TimeLimitMessageHandler.php b/tests/Application/src/Handler/TimeLimitMessageHandler.php deleted file mode 100644 index 8a42669..0000000 --- a/tests/Application/src/Handler/TimeLimitMessageHandler.php +++ /dev/null @@ -1,23 +0,0 @@ -logger->info('Time Limit Message : '.$message->durationInSeconds); - sleep($message->durationInSeconds); - } -} diff --git a/tests/Unit/MessengerIntegration/LimitNbMessageTest.php b/tests/Unit/MessengerIntegration/LimitNbMessageTest.php deleted file mode 100644 index b32c722..0000000 --- a/tests/Unit/MessengerIntegration/LimitNbMessageTest.php +++ /dev/null @@ -1,78 +0,0 @@ -get('doctrine.dbal.default_connection'); - $connexion->rollBack(); - } - - public function testLimitMessage(): void - { - $serviceName = 'win32service.demo.messenger.async.0'; - self::bootKernel(); - $container = static::getContainer(); - - /** @var Connection $connexion */ - $connexion = $container->get('doctrine.dbal.default_connection'); - $connexion->beginTransaction(); - $connexion->query('DELETE FROM messenger_messages'); - /** @var MessageBusInterface $messengerBus */ - $messengerBus = $container->get('messenger.bus.default'); - $messagesTotal = 20; - for ($i = 1; $i <= $messagesTotal; ++$i) { - $messengerBus->dispatch(new TestMessage('message '.$i)); - } - - $c = $connexion->query('SELECT count(*) FROM messenger_messages WHERE queue_name = \'default\''); - - $this->assertSame($messagesTotal, (int) $c->fetchOne()); - - $runnerManager = $container->get(RunnerManager::class); - $serviceConfigurationManager = $container->get(ServiceConfigurationManager::class); - /** @var MessengerServiceRunner $runner */ - $runner = $runnerManager->getRunner($serviceConfigurationManager->getRunnerAliasForServiceId($serviceName)); - $runner->setServiceId(new ServiceIdentifier($serviceName)); - $runner->doRun($messagesTotal, 0); - - $rClass = new \ReflectionClass(AbstractServiceRunner::class); - $value = $rClass->getProperty('stopRequested'); - $value->setAccessible(true); - - $this->assertTrue($value->getValue($runner)); - - $c = $connexion->query('SELECT count(*) FROM messenger_messages WHERE queue_name = \'default\' AND delivered_at IS NULL'); - - $this->assertSame(10, (int) $c->fetchOne()); - - $c = $connexion->query('SELECT count(*) FROM messenger_messages WHERE queue_name = \'default\' AND delivered_at IS NOT NULL'); - // Other message has been deleted, only last processed message is keep - $this->assertSame(1, (int) $c->fetchOne()); - } -} diff --git a/tests/Unit/MessengerIntegration/MemoryLimitMessageTest.php b/tests/Unit/MessengerIntegration/MemoryLimitMessageTest.php deleted file mode 100644 index e283992..0000000 --- a/tests/Unit/MessengerIntegration/MemoryLimitMessageTest.php +++ /dev/null @@ -1,77 +0,0 @@ -get('doctrine.dbal.default_connection'); - $connexion->rollBack(); - } - - public function testMemoryLimitMessage(): void - { - $serviceName = 'win32service.demo.messenger.async.0'; - self::bootKernel(); - $container = static::getContainer(); - - /** @var Connection $connexion */ - $connexion = $container->get('doctrine.dbal.default_connection'); - $connexion->beginTransaction(); - $connexion->query('DELETE FROM messenger_messages'); - /** @var MessageBusInterface $messengerBus */ - $messengerBus = $container->get('messenger.bus.default'); - $messengerBus->dispatch(new TestMemoryLimitMessage( /* 129 Mio */1024 * 1024 * 129)); - $messengerBus->dispatch(new TestMessage('message 1')); - - $c = $connexion->query('SELECT count(*) FROM messenger_messages WHERE queue_name = \'default\''); - - $this->assertSame(2, (int) $c->fetchOne()); - - $runnerManager = $container->get(RunnerManager::class); - $serviceConfigurationManager = $container->get(ServiceConfigurationManager::class); - /** @var MessengerServiceRunner $runner */ - $runner = $runnerManager->getRunner($serviceConfigurationManager->getRunnerAliasForServiceId($serviceName)); - $runner->setServiceId(new ServiceIdentifier($serviceName)); - $runner->doRun(5, 0); - - $rClass = new \ReflectionClass(AbstractServiceRunner::class); - $value = $rClass->getProperty('stopRequested'); - $value->setAccessible(true); - - $this->assertTrue($value->getValue($runner)); - - $c = $connexion->query('SELECT count(*) FROM messenger_messages WHERE queue_name = \'default\' AND delivered_at IS NULL'); - - $this->assertSame(1, (int) $c->fetchOne()); - - $c = $connexion->query('SELECT count(*) FROM messenger_messages WHERE queue_name = \'default\' AND delivered_at IS NOT NULL'); - - $this->assertSame(1, (int) $c->fetchOne()); - } -} diff --git a/tests/Unit/MessengerIntegration/MessageTest.php b/tests/Unit/MessengerIntegration/MessageTest.php deleted file mode 100644 index 9a527f1..0000000 --- a/tests/Unit/MessengerIntegration/MessageTest.php +++ /dev/null @@ -1,68 +0,0 @@ -get('doctrine.dbal.default_connection'); - $connexion->rollBack(); - } - - public function testNormalMessage(): void - { - $serviceName = 'win32service.demo.messenger.async.0'; - self::bootKernel(); - $container = static::getContainer(); - - /** @var Connection $connexion */ - $connexion = $container->get('doctrine.dbal.default_connection'); - $connexion->beginTransaction(); - $connexion->query('DELETE FROM messenger_messages'); - /** @var MessageBusInterface $messengerBus */ - $messengerBus = $container->get('messenger.bus.default'); - $messengerBus->dispatch(new TestMessage('message 1')); - - $c = $connexion->query('SELECT count(*) FROM messenger_messages WHERE queue_name = \'default\''); - - $this->assertSame(1, (int) $c->fetchOne()); - - $runnerManager = $container->get(RunnerManager::class); - $serviceConfigurationManager = $container->get(ServiceConfigurationManager::class); - /** @var MessengerServiceRunner $runner */ - $runner = $runnerManager->getRunner($serviceConfigurationManager->getRunnerAliasForServiceId($serviceName)); - $runner->setServiceId(new ServiceIdentifier($serviceName)); - $runner->doRun(1, 0); - - $c = $connexion->query('SELECT count(*) FROM messenger_messages WHERE queue_name = \'default\' AND delivered_at IS NULL'); - - $this->assertSame(0, (int) $c->fetchOne()); - - $c = $connexion->query('SELECT count(*) FROM messenger_messages WHERE queue_name = \'default\' AND delivered_at IS NOT NULL'); - - $this->assertSame(1, (int) $c->fetchOne()); - } -} diff --git a/tests/Unit/MessengerIntegration/RetryMessageTest.php b/tests/Unit/MessengerIntegration/RetryMessageTest.php deleted file mode 100644 index 05459c2..0000000 --- a/tests/Unit/MessengerIntegration/RetryMessageTest.php +++ /dev/null @@ -1,64 +0,0 @@ -get('doctrine.dbal.default_connection'); - $connexion->rollBack(); - } - - public function testRetryMessage(): void - { - $serviceName = 'win32service.demo.messenger.async.0'; - self::bootKernel(); - $container = static::getContainer(); - - /** @var Connection $connexion */ - $connexion = $container->get('doctrine.dbal.default_connection'); - $connexion->beginTransaction(); - $connexion->query('DELETE FROM messenger_messages'); - /** @var MessageBusInterface $messengerBus */ - $messengerBus = $container->get('messenger.bus.default'); - $messengerBus->dispatch(new TestRetryMessage()); - - $c = $connexion->query('SELECT count(*) FROM messenger_messages WHERE queue_name = \'default\''); - - $this->assertSame(1, (int) $c->fetchOne()); - - $runnerManager = $container->get(RunnerManager::class); - $serviceConfigurationManager = $container->get(ServiceConfigurationManager::class); - /** @var MessengerServiceRunner $runner */ - $runner = $runnerManager->getRunner($serviceConfigurationManager->getRunnerAliasForServiceId($serviceName)); - $runner->setServiceId(new ServiceIdentifier($serviceName)); - $runner->doRun(1, 0); - - $c = $connexion->query('SELECT count(*) FROM messenger_messages WHERE queue_name = \'default\''); - - $this->assertSame(2, (int) $c->fetchOne()); - } -} diff --git a/tests/Unit/MessengerIntegration/TimeLimitMessageTest.php b/tests/Unit/MessengerIntegration/TimeLimitMessageTest.php deleted file mode 100644 index e8baa4f..0000000 --- a/tests/Unit/MessengerIntegration/TimeLimitMessageTest.php +++ /dev/null @@ -1,77 +0,0 @@ -get('doctrine.dbal.default_connection'); - $connexion->rollBack(); - } - - public function testTimeLimitMessage(): void - { - $serviceName = 'win32service.demo.messenger.async.0'; - self::bootKernel(); - $container = static::getContainer(); - - /** @var Connection $connexion */ - $connexion = $container->get('doctrine.dbal.default_connection'); - $connexion->beginTransaction(); - $connexion->query('DELETE FROM messenger_messages'); - /** @var MessageBusInterface $messengerBus */ - $messengerBus = $container->get('messenger.bus.default'); - $messengerBus->dispatch(new TestTimeLimitMessage(2)); - $messengerBus->dispatch(new TestMessage('message 1')); - - $c = $connexion->query('SELECT count(*) FROM messenger_messages WHERE queue_name = \'default\''); - - $this->assertSame(2, (int) $c->fetchOne()); - - $runnerManager = $container->get(RunnerManager::class); - $serviceConfigurationManager = $container->get(ServiceConfigurationManager::class); - /** @var MessengerServiceRunner $runner */ - $runner = $runnerManager->getRunner($serviceConfigurationManager->getRunnerAliasForServiceId($serviceName)); - $runner->setServiceId(new ServiceIdentifier($serviceName)); - $runner->doRun(5, 0); - - $rClass = new \ReflectionClass(AbstractServiceRunner::class); - $value = $rClass->getProperty('stopRequested'); - $value->setAccessible(true); - - $this->assertTrue($value->getValue($runner)); - - $c = $connexion->query('SELECT count(*) FROM messenger_messages WHERE queue_name = \'default\' AND delivered_at IS NULL'); - - $this->assertSame(1, (int) $c->fetchOne()); - - $c = $connexion->query('SELECT count(*) FROM messenger_messages WHERE queue_name = \'default\' AND delivered_at IS NOT NULL'); - - $this->assertSame(1, (int) $c->fetchOne()); - } -} diff --git a/tests/Win32serviceState.php b/tests/Win32serviceState.php deleted file mode 100644 index d3db917..0000000 --- a/tests/Win32serviceState.php +++ /dev/null @@ -1,85 +0,0 @@ -setServiceName($serviceName); -} - -function win32_set_service_status(int $newState): void -{ - Win32serviceState::getInstance()->changeState($newState); -} - -function win32_get_last_control_message(): int -{ - return Win32serviceState::getInstance()->getLastControlMessage(); -} - -class Win32serviceState -{ - private static ?self $instance = null; - - private int $state = WIN32_SERVICE_STOPPED; - - private ?string $serviceName = null; - - private int $lastControlMessage = WIN32_SERVICE_CONTROL_INTERROGATE; - - public static function getInstance(): self - { - if (self::$instance === null) { - self::$instance = new self(); - } - - return self::$instance; - } - - public static function reset(): void - { - self::$instance = null; - } - - public function setServiceName(string $serviceName): bool - { - if ($this->serviceName === null) { - $this->serviceName = $serviceName; - - return true; - } - - return false; - } - - public function getServiceName(): string - { - return $this->serviceName; - } - - public function changeState(int $newState): void - { - $this->state = $newState; - } - - public function getState(): int - { - return $this->state; - } - - public function getLastControlMessage(): int - { - return $this->lastControlMessage; - } - - public function setLastControlMessage(int $newControlMessage): void - { - $this->lastControlMessage = $newControlMessage; - } -} diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index cebbef5..0000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,13 +0,0 @@ -bootEnv(__DIR__.'/Application/.env', 'test'); -}