Skip to content

Commit

Permalink
Merge pull request #204 from kevin-dutra/203-too-many-in-queue-item
Browse files Browse the repository at this point in the history
#203 Too many messages per deletion queue item
  • Loading branch information
jhedstrom authored Aug 15, 2017
2 parents ac95b85 + d867bed commit c65aafe
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/MessagePurgeBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ public static function create(ContainerInterface $container, array $configuratio
* {@inheritdoc}
*/
public function process(array $ids) {
$this->queue->createItem($ids);
if (!empty($ids)) {
foreach (array_chunk($ids, MessagePurgeInterface::MESSAGE_DELETE_SIZE) as $queue_set) {
$this->queue->createItem($queue_set);
}
}
}

/**
Expand Down
53 changes: 53 additions & 0 deletions tests/src/Unit/Plugin/MessagePurge/DaysTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Drupal\Tests\message\Unit\Plugin\MessagePurge;

use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Queue\QueueInterface;
use Drupal\message\MessagePurgeInterface;
use Drupal\message\Plugin\MessagePurge\Days;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* Unit tests for the days purge plugin.
*
* @coversDefaultClass \Drupal\message\Plugin\MessagePurge\Days
*
* @group Message
*/
class DaysTest extends UnitTestCase {

/**
* Test processing zero message.
*
* @covers ::process
*/
public function testProcessNone() {
$query = $this->prophesize(QueryInterface::class)->reveal();
$request_stack = $this->prophesize(RequestStack::class)->reveal();
$queue = $this->prophesize(QueueInterface::class);
$queue->createItem(Argument::any())->shouldNotBeCalled();
$plugin = new Days([], 'days', [], $query, $queue->reveal(), $request_stack);
$plugin->process([]);
}

/**
* Tests processing more than defined queue item limit.
*
* @covers ::process
*/
public function testProcess() {
$query = $this->prophesize(QueryInterface::class)->reveal();
$request_stack = $this->prophesize(RequestStack::class)->reveal();
$queue = $this->prophesize(QueueInterface::class);
$queue->createItem(Argument::size(MessagePurgeInterface::MESSAGE_DELETE_SIZE))->shouldBeCalledTimes(1);
$queue->createItem(Argument::size(1))->shouldBeCalledTimes(1);
$plugin = new Days([], 'days', [], $query, $queue->reveal(), $request_stack);

$messages = range(1, MessagePurgeInterface::MESSAGE_DELETE_SIZE + 1);
$plugin->process($messages);
}

}

0 comments on commit c65aafe

Please sign in to comment.