|
17 | 17 | use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent;
|
18 | 18 | use Symfony\Component\Messenger\Event\WorkerMessageReceivedEvent;
|
19 | 19 | use Symfony\Component\Messenger\Event\WorkerStoppedEvent;
|
| 20 | +use Symfony\Component\Messenger\Exception\HandlerFailedException; |
20 | 21 | use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
|
21 | 22 | use Symfony\Component\Messenger\MessageBusInterface;
|
22 | 23 | use Symfony\Component\Messenger\Retry\RetryStrategyInterface;
|
@@ -120,6 +121,37 @@ public function testDispatchCausesRetry()
|
120 | 121 | $this->assertSame(1, $receiver->getAcknowledgeCount());
|
121 | 122 | }
|
122 | 123 |
|
| 124 | + public function testUnrecoverableMessageHandlingExceptionPreventsRetries() |
| 125 | + { |
| 126 | + $envelope1 = new Envelope(new DummyMessage('Unwrapped Exception'), [new SentStamp('Some\Sender', 'transport1')]); |
| 127 | + $envelope2 = new Envelope(new DummyMessage('Wrapped Exception'), [new SentStamp('Some\Sender', 'transport1')]); |
| 128 | + |
| 129 | + $receiver = new DummyReceiver([ |
| 130 | + [$envelope1], |
| 131 | + [$envelope2], |
| 132 | + ]); |
| 133 | + |
| 134 | + $bus = $this->getMockBuilder(MessageBusInterface::class)->getMock(); |
| 135 | + $bus->expects($this->at(0))->method('dispatch')->willThrowException(new UnrecoverableMessageHandlingException()); |
| 136 | + $bus->expects($this->at(1))->method('dispatch')->willThrowException( |
| 137 | + new HandlerFailedException($envelope2, [new UnrecoverableMessageHandlingException()]) |
| 138 | + ); |
| 139 | + |
| 140 | + $retryStrategy = $this->getMockBuilder(RetryStrategyInterface::class)->getMock(); |
| 141 | + $retryStrategy->expects($this->never())->method('isRetryable')->willReturn(true); |
| 142 | + |
| 143 | + $worker = new Worker(['transport1' => $receiver], $bus, ['transport1' => $retryStrategy]); |
| 144 | + $worker->run([], function (?Envelope $envelope) use ($worker) { |
| 145 | + // stop after the messages finish |
| 146 | + if (null === $envelope) { |
| 147 | + $worker->stop(); |
| 148 | + } |
| 149 | + }); |
| 150 | + |
| 151 | + // message was rejected |
| 152 | + $this->assertSame(2, $receiver->getRejectCount()); |
| 153 | + } |
| 154 | + |
123 | 155 | public function testDispatchCausesRejectWhenNoRetry()
|
124 | 156 | {
|
125 | 157 | $receiver = new DummyReceiver([
|
|
0 commit comments