Skip to content

Commit 116ee4a

Browse files
Merge branch '6.2' into 6.3
* 6.2: [HttpKernel] Account for Response::getDate() possibly returning a DateTimeImmutable [Messenger] Respect `isRetryable` decision of the retry strategy when deciding if failed message should be re-delivered
2 parents 03cbfad + 6e74955 commit 116ee4a

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

EventListener/SendFailedMessageForRetryListener.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ public static function getSubscribedEvents(): array
120120

121121
private function shouldRetry(\Throwable $e, Envelope $envelope, RetryStrategyInterface $retryStrategy): bool
122122
{
123-
if ($e instanceof RecoverableExceptionInterface) {
123+
$isRetryable = $retryStrategy->isRetryable($envelope, $e);
124+
if ($isRetryable && $e instanceof RecoverableExceptionInterface) {
124125
return true;
125126
}
126127

@@ -129,7 +130,7 @@ private function shouldRetry(\Throwable $e, Envelope $envelope, RetryStrategyInt
129130
if ($e instanceof HandlerFailedException) {
130131
$shouldNotRetry = true;
131132
foreach ($e->getNestedExceptions() as $nestedException) {
132-
if ($nestedException instanceof RecoverableExceptionInterface) {
133+
if ($isRetryable && $nestedException instanceof RecoverableExceptionInterface) {
133134
return true;
134135
}
135136

@@ -147,7 +148,7 @@ private function shouldRetry(\Throwable $e, Envelope $envelope, RetryStrategyInt
147148
return false;
148149
}
149150

150-
return $retryStrategy->isRetryable($envelope, $e);
151+
return $isRetryable;
151152
}
152153

153154
private function getRetryStrategyForTransport(string $alias): ?RetryStrategyInterface

Tests/EventListener/SendFailedMessageForRetryListenerTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testRecoverableStrategyCausesRetry()
6363
$senderLocator->expects($this->once())->method('has')->willReturn(true);
6464
$senderLocator->expects($this->once())->method('get')->willReturn($sender);
6565
$retryStategy = $this->createMock(RetryStrategyInterface::class);
66-
$retryStategy->expects($this->never())->method('isRetryable');
66+
$retryStategy->expects($this->once())->method('isRetryable')->willReturn(true);
6767
$retryStategy->expects($this->once())->method('getWaitingTime')->willReturn(1000);
6868
$retryStrategyLocator = $this->createMock(ContainerInterface::class);
6969
$retryStrategyLocator->expects($this->once())->method('has')->willReturn(true);
@@ -78,6 +78,27 @@ public function testRecoverableStrategyCausesRetry()
7878
$listener->onMessageFailed($event);
7979
}
8080

81+
public function testRetryIsOnlyAllowedWhenPermittedByRetryStrategy()
82+
{
83+
$senderLocator = $this->createMock(ContainerInterface::class);
84+
$senderLocator->expects($this->never())->method('has');
85+
$senderLocator->expects($this->never())->method('get');
86+
$retryStrategy = $this->createMock(RetryStrategyInterface::class);
87+
$retryStrategy->expects($this->once())->method('isRetryable')->willReturn(false);
88+
$retryStrategy->expects($this->never())->method('getWaitingTime');
89+
$retryStrategyLocator = $this->createMock(ContainerInterface::class);
90+
$retryStrategyLocator->expects($this->once())->method('has')->willReturn(true);
91+
$retryStrategyLocator->expects($this->once())->method('get')->willReturn($retryStrategy);
92+
93+
$listener = new SendFailedMessageForRetryListener($senderLocator, $retryStrategyLocator);
94+
95+
$exception = new RecoverableMessageHandlingException('retry');
96+
$envelope = new Envelope(new \stdClass());
97+
$event = new WorkerMessageFailedEvent($envelope, 'my_receiver', $exception);
98+
99+
$listener->onMessageFailed($event);
100+
}
101+
81102
public function testEnvelopeIsSentToTransportOnRetry()
82103
{
83104
$exception = new \Exception('no!');

0 commit comments

Comments
 (0)