zenstruck / messenger-test

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

`TestTransport::processRecursive()` #10

Closed kbond closed 3 years ago

kbond commented 3 years ago

When processing your queue, if some handler's add more messages to your queue, there should be an option to recursively process these as well.

I'm thinking:

  1. Passing -1 to TestTransport::process() enables this.
  2. Add TestTransport::processRecursive() shortcut.
OskarStark commented 3 years ago

I think its exactly the issue I am facing right now 🤔

I am doing sth like:

$this->bus->dispatch(
    (new Envelope(SetNewConfirmationStatus::create($abo->getId(), $confirmationStatus)))
        ->with(new DispatchAfterCurrentBusStamp())
);

in my message handlers and I want to assertContains(SetNewConfirmationStatus::class, 1), but it is failing.

If you want you can have a look here: https://github.com/datana-gmbh/cockpit/pull/1320

kbond commented 3 years ago

Do you think this should be how process() works generally?

$this->messenger()->process(); // continues processing recursively until no messages left on queue
$this->messenger()->process(5); // process recursively until 5 messages processed - fail if queue emptied before 5 processed

I'm thinking yes - can you think of any downsides?

OskarStark commented 3 years ago

Exactly, running process() would be perfect to process recursively.

Right now not.

But right now a downside is "assertNotContains()", because it is not true if not alle messages are processed recursively, which would be fixed as well afterwards