zenstruck / messenger-test

Assertions and helpers for testing your symfony/messenger queues.
MIT License
223 stars 15 forks source link

[minor] give a name to the transport in the Worker #34

Closed nikophil closed 2 years ago

nikophil commented 2 years ago

Hello!

I hope this was not made on purpose, but in order to best mimic the behavior of messenger, the receivers need to have a name in the worker, as seen in Symfony\Component\Messenger\Command\ConsumeMessagesCommand

// Symfony\Component\Messenger\Command\ConsumeMessagesCommand
protected function execute(InputInterface $input, OutputInterface $output): int
{
        $receivers = [];
        foreach ($receiverNames = $input->getArgument('receivers') as $receiverName) {
            //...
            $receivers[$receiverName] = $this->receiverLocator->get($receiverName);
        }

        // ...
        $worker = new Worker($receivers, $bus, $this->eventDispatcher, $this->logger);
        // ...
}

Otherwise, we cannot reproduce the retry behavior because the computation of retryStrategy is based on transport's name. Yet, IMO, it could be a good thing to be able to reproduce retry behavior in tests since I've already had some complex bugs in retry scenario.

nikophil commented 2 years ago

I've rebased the PR.

Is this related to #2?

I think this isn't related to #2. Failure transport is only related to retry if the event is setForRetry

Should/could we add tests to ensure failed messages are added to a failed transport.

I think we should not behave as if it does not exist, and then at least configure max_retries: 1 for one transport and test that in blocking and unblocking modes a failing message is dispatched twice