Skip to content

Commit

Permalink
bug #34474 [Messenger] Ignore stamps in in-memory transport (tienvx)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.4 branch.

Discussion
----------

[Messenger] Ignore stamps in in-memory transport

| Q             | A
| ------------- | ---
| Branch?       | 4.4 <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | N/A <!-- prefix each issue number with "Fix #", if any -->
| License       | MIT
| Doc PR        | N/A <!-- required for new features -->

Stamps can be added/removed to/from message during handling. Ignore stamps so that we can ack/reject them correctly.

<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/roadmap):
 - Always add tests and ensure they pass.
 - Never break backward compatibility (see https://symfony.com/bc).
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too.)
 - Features and deprecations must be submitted against branch master.
-->

Commits
-------

b435b1a [Messenger] Ignore stamps in in-memory transport
  • Loading branch information
sroze committed Nov 21, 2019
2 parents a7fe2b2 + b435b1a commit bfae515
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Tests\Fixtures\AnEnvelopeStamp;
use Symfony\Component\Messenger\Transport\InMemoryTransport;

/**
Expand Down Expand Up @@ -50,6 +51,19 @@ public function testQueue()
$this->assertSame([], $this->transport->get());
}

public function testAcknowledgeSameMessageWithDifferentStamps()
{
$envelope1 = new Envelope(new \stdClass(), [new AnEnvelopeStamp()]);
$this->transport->send($envelope1);
$envelope2 = new Envelope(new \stdClass(), [new AnEnvelopeStamp()]);
$this->transport->send($envelope2);
$this->assertSame([$envelope1, $envelope2], $this->transport->get());
$this->transport->ack($envelope1->with(new AnEnvelopeStamp()));
$this->assertSame([$envelope2], $this->transport->get());
$this->transport->reject($envelope2->with(new AnEnvelopeStamp()));
$this->assertSame([], $this->transport->get());
}

public function testAck()
{
$envelope = new Envelope(new \stdClass());
Expand Down
Expand Up @@ -55,7 +55,7 @@ public function get(): iterable
public function ack(Envelope $envelope): void
{
$this->acknowledged[] = $envelope;
$id = spl_object_hash($envelope);
$id = spl_object_hash($envelope->getMessage());
unset($this->queue[$id]);
}

Expand All @@ -65,7 +65,7 @@ public function ack(Envelope $envelope): void
public function reject(Envelope $envelope): void
{
$this->rejected[] = $envelope;
$id = spl_object_hash($envelope);
$id = spl_object_hash($envelope->getMessage());
unset($this->queue[$id]);
}

Expand All @@ -75,7 +75,7 @@ public function reject(Envelope $envelope): void
public function send(Envelope $envelope): Envelope
{
$this->sent[] = $envelope;
$id = spl_object_hash($envelope);
$id = spl_object_hash($envelope->getMessage());
$this->queue[$id] = $envelope;

return $envelope;
Expand Down

0 comments on commit bfae515

Please sign in to comment.