Merge branch '4.3' into 4.4
* 4.3: fix tests [Validator] Added support for validation of giga values Fix Debug component tests [Messenger] fixed UnrecoverableExceptionInterface handling in Worker (fixes #32325) [Messenger] pass transport name to factory
This commit is contained in:
commit
0d8f5fe985
@ -1742,7 +1742,7 @@ class FrameworkExtension extends Extension
|
|||||||
|
|
||||||
$transportDefinition = (new Definition(TransportInterface::class))
|
$transportDefinition = (new Definition(TransportInterface::class))
|
||||||
->setFactory([new Reference('messenger.transport_factory'), 'createTransport'])
|
->setFactory([new Reference('messenger.transport_factory'), 'createTransport'])
|
||||||
->setArguments([$transport['dsn'], $transport['options'], new Reference($serializerId)])
|
->setArguments([$transport['dsn'], $transport['options'] + ['transport_name' => $name], new Reference($serializerId)])
|
||||||
->addTag('messenger.receiver', ['alias' => $name])
|
->addTag('messenger.receiver', ['alias' => $name])
|
||||||
;
|
;
|
||||||
$container->setDefinition($transportId = 'messenger.transport.'.$name, $transportDefinition);
|
$container->setDefinition($transportId = 'messenger.transport.'.$name, $transportDefinition);
|
||||||
|
@ -706,7 +706,7 @@ abstract class FrameworkExtensionTest extends TestCase
|
|||||||
$this->assertEquals([new Reference('messenger.transport_factory'), 'createTransport'], $transportFactory);
|
$this->assertEquals([new Reference('messenger.transport_factory'), 'createTransport'], $transportFactory);
|
||||||
$this->assertCount(3, $transportArguments);
|
$this->assertCount(3, $transportArguments);
|
||||||
$this->assertSame('amqp://localhost/%2f/messages?exchange_name=exchange_name', $transportArguments[0]);
|
$this->assertSame('amqp://localhost/%2f/messages?exchange_name=exchange_name', $transportArguments[0]);
|
||||||
$this->assertEquals(['queue' => ['name' => 'Queue']], $transportArguments[1]);
|
$this->assertEquals(['queue' => ['name' => 'Queue'], 'transport_name' => 'customised'], $transportArguments[1]);
|
||||||
$this->assertEquals(new Reference('messenger.transport.native_php_serializer'), $transportArguments[2]);
|
$this->assertEquals(new Reference('messenger.transport.native_php_serializer'), $transportArguments[2]);
|
||||||
|
|
||||||
$this->assertTrue($container->hasDefinition('messenger.transport.amqp.factory'));
|
$this->assertTrue($container->hasDefinition('messenger.transport.amqp.factory'));
|
||||||
|
@ -17,6 +17,7 @@ use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;
|
|||||||
use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent;
|
use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent;
|
||||||
use Symfony\Component\Messenger\Event\WorkerMessageReceivedEvent;
|
use Symfony\Component\Messenger\Event\WorkerMessageReceivedEvent;
|
||||||
use Symfony\Component\Messenger\Event\WorkerStoppedEvent;
|
use Symfony\Component\Messenger\Event\WorkerStoppedEvent;
|
||||||
|
use Symfony\Component\Messenger\Exception\HandlerFailedException;
|
||||||
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
|
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
|
||||||
use Symfony\Component\Messenger\MessageBusInterface;
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
use Symfony\Component\Messenger\Retry\RetryStrategyInterface;
|
use Symfony\Component\Messenger\Retry\RetryStrategyInterface;
|
||||||
@ -120,6 +121,37 @@ class WorkerTest extends TestCase
|
|||||||
$this->assertSame(1, $receiver->getAcknowledgeCount());
|
$this->assertSame(1, $receiver->getAcknowledgeCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUnrecoverableMessageHandlingExceptionPreventsRetries()
|
||||||
|
{
|
||||||
|
$envelope1 = new Envelope(new DummyMessage('Unwrapped Exception'), [new SentStamp('Some\Sender', 'transport1')]);
|
||||||
|
$envelope2 = new Envelope(new DummyMessage('Wrapped Exception'), [new SentStamp('Some\Sender', 'transport1')]);
|
||||||
|
|
||||||
|
$receiver = new DummyReceiver([
|
||||||
|
[$envelope1],
|
||||||
|
[$envelope2],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$bus = $this->getMockBuilder(MessageBusInterface::class)->getMock();
|
||||||
|
$bus->expects($this->at(0))->method('dispatch')->willThrowException(new UnrecoverableMessageHandlingException());
|
||||||
|
$bus->expects($this->at(1))->method('dispatch')->willThrowException(
|
||||||
|
new HandlerFailedException($envelope2, [new UnrecoverableMessageHandlingException()])
|
||||||
|
);
|
||||||
|
|
||||||
|
$retryStrategy = $this->getMockBuilder(RetryStrategyInterface::class)->getMock();
|
||||||
|
$retryStrategy->expects($this->never())->method('isRetryable')->willReturn(true);
|
||||||
|
|
||||||
|
$worker = new Worker(['transport1' => $receiver], $bus, ['transport1' => $retryStrategy]);
|
||||||
|
$worker->run([], function (?Envelope $envelope) use ($worker) {
|
||||||
|
// stop after the messages finish
|
||||||
|
if (null === $envelope) {
|
||||||
|
$worker->stop();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// message was rejected
|
||||||
|
$this->assertSame(2, $receiver->getRejectCount());
|
||||||
|
}
|
||||||
|
|
||||||
public function testDispatchCausesRejectWhenNoRetry()
|
public function testDispatchCausesRejectWhenNoRetry()
|
||||||
{
|
{
|
||||||
$receiver = new DummyReceiver([
|
$receiver = new DummyReceiver([
|
||||||
|
@ -190,6 +190,20 @@ class Worker implements WorkerInterface
|
|||||||
|
|
||||||
private function shouldRetry(\Throwable $e, Envelope $envelope, RetryStrategyInterface $retryStrategy): bool
|
private function shouldRetry(\Throwable $e, Envelope $envelope, RetryStrategyInterface $retryStrategy): bool
|
||||||
{
|
{
|
||||||
|
// 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 UnrecoverableExceptionInterface) {
|
||||||
|
$shouldNotRetry = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($shouldNotRetry) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($e instanceof UnrecoverableExceptionInterface) {
|
if ($e instanceof UnrecoverableExceptionInterface) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -105,8 +105,10 @@ class File extends Constraint
|
|||||||
$factors = [
|
$factors = [
|
||||||
'k' => 1000,
|
'k' => 1000,
|
||||||
'ki' => 1 << 10,
|
'ki' => 1 << 10,
|
||||||
'm' => 1000000,
|
'm' => 1000 * 1000,
|
||||||
'mi' => 1 << 20,
|
'mi' => 1 << 20,
|
||||||
|
'g' => 1000 * 1000 * 1000,
|
||||||
|
'gi' => 1 << 30,
|
||||||
];
|
];
|
||||||
if (ctype_digit((string) $maxSize)) {
|
if (ctype_digit((string) $maxSize)) {
|
||||||
$this->maxSize = (int) $maxSize;
|
$this->maxSize = (int) $maxSize;
|
||||||
|
@ -97,6 +97,10 @@ class FileTest extends TestCase
|
|||||||
['1MI', 1048576, true],
|
['1MI', 1048576, true],
|
||||||
['3m', 3000000, false],
|
['3m', 3000000, false],
|
||||||
['3M', 3000000, false],
|
['3M', 3000000, false],
|
||||||
|
['1gi', 1073741824, true],
|
||||||
|
['1GI', 1073741824, true],
|
||||||
|
['4g', 4000000000, false],
|
||||||
|
['4G', 4000000000, false],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,8 +111,6 @@ class FileTest extends TestCase
|
|||||||
['foo'],
|
['foo'],
|
||||||
['1Ko'],
|
['1Ko'],
|
||||||
['1kio'],
|
['1kio'],
|
||||||
['1G'],
|
|
||||||
['1Gi'],
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user