Skip to content

Commit

Permalink
Merge branch '7.1' into 7.2
Browse files Browse the repository at this point in the history
* 7.1:
  [AssetMapper] Fix `JavaScriptImportPathCompiler` regex for non-latin characters
  Definition::$class may not be class-string
  require Cache component versions compatible with Redis 6.1
  [Twitter][Notifier] Fix post INIT upload
  [Messenger][RateLimiter] fix additional message handled when using a rate limiter
  [Serializer] Revert default groups
  [Serializer] fixed object normalizer for a class with `cancel` method
  Fix bucket size reduce when previously created with bigger size
  • Loading branch information
xabbuh committed Nov 9, 2024
2 parents 3722a28 + 86d9aea commit ca6f254
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Tests/WorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface;
use Symfony\Component\Messenger\Worker;
use Symfony\Component\RateLimiter\RateLimiterFactory;
use Symfony\Component\RateLimiter\Reservation;
use Symfony\Component\RateLimiter\Storage\InMemoryStorage;

/**
Expand Down Expand Up @@ -439,21 +440,21 @@ public function testWorkerRateLimitMessages()
$envelope = [
new Envelope(new DummyMessage('message1')),
new Envelope(new DummyMessage('message2')),
new Envelope(new DummyMessage('message3')),
new Envelope(new DummyMessage('message4')),
];
$receiver = new DummyReceiver([$envelope]);

$bus = $this->createMock(MessageBusInterface::class);
$bus->method('dispatch')->willReturnArgument(0);

$eventDispatcher = new EventDispatcher();
$eventDispatcher->addSubscriber(new StopWorkerOnMessageLimitListener(2));
$eventDispatcher->addSubscriber(new StopWorkerOnMessageLimitListener(4));

$rateLimitCount = 0;
$listener = function (WorkerRateLimitedEvent $event) use (&$rateLimitCount) {
$eventDispatcher->addListener(WorkerRateLimitedEvent::class, static function () use (&$rateLimitCount) {
++$rateLimitCount;
$event->getLimiter()->reset(); // Reset limiter to continue test
};
$eventDispatcher->addListener(WorkerRateLimitedEvent::class, $listener);
});

$rateLimitFactory = new RateLimiterFactory([
'id' => 'bus',
Expand All @@ -462,11 +463,14 @@ public function testWorkerRateLimitMessages()
'interval' => '1 minute',
], new InMemoryStorage());

ClockMock::register(Reservation::class);
ClockMock::register(InMemoryStorage::class);

$worker = new Worker(['bus' => $receiver], $bus, $eventDispatcher, null, ['bus' => $rateLimitFactory], new MockClock());
$worker->run();

$this->assertCount(2, $receiver->getAcknowledgedEnvelopes());
$this->assertEquals(1, $rateLimitCount);
$this->assertSame(4, $receiver->getAcknowledgeCount());
$this->assertSame(3, $rateLimitCount);
}

public function testWorkerShouldLogOnStop()
Expand Down
1 change: 1 addition & 0 deletions Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ private function rateLimit(string $transportName): void

$this->eventDispatcher?->dispatch(new WorkerRateLimitedEvent($rateLimiter, $transportName));
$rateLimiter->reserve()->wait();
$rateLimiter->consume();
}

private function flush(bool $force): bool
Expand Down

0 comments on commit ca6f254

Please sign in to comment.