-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Messenger: capture_soft_fails:false doesn't work (#353)
* Add regression test * Apply fix by lowering the MessengerListener priority * Add test for direct capturing from the Messenger * Fix prefer-lowest in CI * Skip test properly in prefer-lowest
- Loading branch information
Showing
12 changed files
with
316 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
test/End2End/App/Messenger/StaticInMemoryTransportFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.