Skip to content

Messenger: capture_soft_fails:false doesn't work #353

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
merged 6 commits into from
Jul 8, 2020
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
7 changes: 6 additions & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ parameters:
path: test/DependencyInjection/SentryExtensionTest.php

-
message: "#^Method Sentry\\\\SentryBundle\\\\Test\\\\End2End\\\\App\\\\Kernel\\:\\:build\\(\\) has no return typehint specified\\.$#"
message: "#^Comparison operation \"\\>\\=\" between 50102 and 40300 is always true\\.$#"
count: 1
path: test/End2End/App/Kernel.php

Expand All @@ -240,6 +240,11 @@ parameters:
count: 1
path: test/End2End/End2EndTest.php

-
message: "#^Comparison operation \"\\<\" between 50102 and 40300 is always false\\.$#"
count: 1
path: test/End2End/End2EndTest.php

-
message: "#^Method Sentry\\\\SentryBundle\\\\Test\\\\ErrorTypesParserTest\\:\\:testParse\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function getConfigTreeBuilder(): TreeBuilder
$listenerPriorities->scalarNode('console_error')
->defaultValue(128);
$listenerPriorities->scalarNode('worker_error')
->defaultValue(128);
->defaultValue(99);

// Monolog handler configuration
$monologConfiguration = $rootNode->children()
Expand Down
2 changes: 1 addition & 1 deletion test/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testConfigurationDefaults(): void
'console' => 1,
'request_error' => 128,
'console_error' => 128,
'worker_error' => 128,
'worker_error' => 99,
],
'options' => [
'class_serializers' => [],
Expand Down
32 changes: 32 additions & 0 deletions test/End2End/App/Controller/MessengerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Sentry\SentryBundle\Test\End2End\App\Controller;

use Sentry\SentryBundle\Test\End2End\App\Messenger\FooMessage;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\MessageBusInterface;

class MessengerController
{
/** @var MessageBusInterface */
private $messenger;

public function __construct(MessageBusInterface $messenger)
{
$this->messenger = $messenger;
}

public function dispatchMessage(): Response
{
$this->messenger->dispatch(new FooMessage());

return new Response('Success');
}

public function dispatchUnrecoverableMessage(): Response
{
$this->messenger->dispatch(new FooMessage(false));

return new Response('Success');
}
}
14 changes: 9 additions & 5 deletions test/End2End/App/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,35 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Kernel as SymfonyKernel;
use Symfony\Component\Messenger\MessageBusInterface;

class Kernel extends SymfonyKernel
{
/**
* @return BundleInterface[]
*/
public function registerBundles()
public function registerBundles(): array
{
$bundles = [
return [
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new \Symfony\Bundle\MonologBundle\MonologBundle(),
new \Sentry\SentryBundle\SentryBundle(),
];

return $bundles;
}

public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load(__DIR__ . '/config.yml');

if (interface_exists(MessageBusInterface::class) && self::VERSION_ID >= 40300) {
$loader->load(__DIR__ . '/messenger.yml');
}
}

protected function build(ContainerBuilder $container)
protected function build(ContainerBuilder $container): void
{
$container->setParameter('routing_config_dir', __DIR__);

parent::build($container);
}
}
19 changes: 19 additions & 0 deletions test/End2End/App/Messenger/FooMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Sentry\SentryBundle\Test\End2End\App\Messenger;

class FooMessage
{
/** @var bool */
private $shouldRetry;

public function __construct(bool $shouldRetry = true)
{
$this->shouldRetry = $shouldRetry;
}

public function shouldRetry(): bool
{
return $this->shouldRetry;
}
}
19 changes: 19 additions & 0 deletions test/End2End/App/Messenger/FooMessageHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Sentry\SentryBundle\Test\End2End\App\Messenger;

use Symfony\Component\Messenger\Exception\UnrecoverableExceptionInterface;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;

class FooMessageHandler implements MessageHandlerInterface
{
public function __invoke(FooMessage $message): void
{
if (! $message->shouldRetry()) {
throw new class() extends \Exception implements UnrecoverableExceptionInterface {
};
}

throw new \Exception('This is an intentional failure while handling a message of class ' . get_class($message));
}
}
93 changes: 93 additions & 0 deletions test/End2End/App/Messenger/StaticInMemoryTransport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace Sentry\SentryBundle\Test\End2End\App\Messenger;

use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Transport\TransportInterface;

/**
* @see \Symfony\Component\Messenger\Transport\InMemoryTransport
*/
class StaticInMemoryTransport implements TransportInterface
{
/** @var Envelope[] */
private static $sent = [];

/** @var Envelope[] */
private static $acknowledged = [];

/** @var Envelope[] */
private static $rejected = [];

/** @var Envelope[] */
private static $queue = [];

/**
* {@inheritdoc}
*/
public function get(): iterable
{
return array_values(self::$queue);
}

/**
* {@inheritdoc}
*/
public function ack(Envelope $envelope): void
{
self::$acknowledged[] = $envelope;
$id = spl_object_hash($envelope->getMessage());
unset(self::$queue[$id]);
}

/**
* {@inheritdoc}
*/
public function reject(Envelope $envelope): void
{
self::$rejected[] = $envelope;
$id = spl_object_hash($envelope->getMessage());
unset(self::$queue[$id]);
}

/**
* {@inheritdoc}
*/
public function send(Envelope $envelope): Envelope
{
self::$sent[] = $envelope;
$id = spl_object_hash($envelope->getMessage());
self::$queue[$id] = $envelope;

return $envelope;
}

public static function reset(): void
{
self::$sent = self::$queue = self::$rejected = self::$acknowledged = [];
}

/**
* @return Envelope[]
*/
public function getAcknowledged(): array
{
return self::$acknowledged;
}

/**
* @return Envelope[]
*/
public function getRejected(): array
{
return self::$rejected;
}

/**
* @return Envelope[]
*/
public function getSent(): array
{
return self::$sent;
}
}
26 changes: 26 additions & 0 deletions test/End2End/App/Messenger/StaticInMemoryTransportFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Sentry\SentryBundle\Test\End2End\App\Messenger;

use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;

class StaticInMemoryTransportFactory implements TransportFactoryInterface
{
/**
* @param mixed[] $options
*/
public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface
{
return new StaticInMemoryTransport();
}

/**
* @param mixed[] $options
*/
public function supports(string $dsn, array $options): bool
{
return 'static://' === $dsn;
}
}
28 changes: 28 additions & 0 deletions test/End2End/App/messenger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
services:
_defaults:
autoconfigure: true

Sentry\SentryBundle\Test\End2End\App\Messenger\StaticInMemoryTransportFactory:
class: \Sentry\SentryBundle\Test\End2End\App\Messenger\StaticInMemoryTransportFactory

Sentry\SentryBundle\Test\End2End\App\Messenger\FooMessageHandler:
class: \Sentry\SentryBundle\Test\End2End\App\Messenger\FooMessageHandler

Sentry\SentryBundle\Test\End2End\App\Controller\MessengerController:
autowire: true
tags:
- controller.service_arguments

framework:
messenger:
transports:
async:
dsn: 'static://'
retry_strategy:
max_retries: 1
routing:
'*': async

sentry:
messenger:
capture_soft_fails: false
8 changes: 8 additions & 0 deletions test/End2End/App/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ secured200:
subrequest:
path: /subrequest
defaults: { _controller: 'Sentry\SentryBundle\Test\End2End\App\Controller\MainController::subrequest' }

dispatch:
path: /dispatch-message
defaults: { _controller: 'Sentry\SentryBundle\Test\End2End\App\Controller\MessengerController::dispatchMessage' }

dispatch_unrecoverable:
path: /dispatch-unrecoverable-message
defaults: { _controller: 'Sentry\SentryBundle\Test\End2End\App\Controller\MessengerController::dispatchUnrecoverableMessage' }
Loading