Skip to content

Commit

Permalink
Merge pull request #4882 from magento-borg/borg-pr-2.3-develop
Browse files Browse the repository at this point in the history
[borg] MC-5696: Flaky test: Magento\MysqlMq\Model\QueueManagementTest::testAllFlows
  • Loading branch information
nathanjosiah authored Oct 17, 2019
2 parents d271281 + 97f30cc commit 8ec15ae
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\MysqlMq\Model;

/**
Expand All @@ -23,27 +24,26 @@ class QueueManagementTest extends \PHPUnit\Framework\TestCase
protected function setUp()
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->queueManagement = $this->objectManager->create(\Magento\MysqlMq\Model\QueueManagement::class);
$this->queueManagement = $this->objectManager->create(QueueManagement::class);
}

/**
* @magentoDataFixture Magento/MysqlMq/_files/queues.php
*/
public function testAllFlows()
public function testMessageReading()
{
$this->queueManagement->addMessageToQueues('topic1', 'messageBody1', ['queue1', 'queue2']);
$this->queueManagement->addMessageToQueues('topic2', 'messageBody2', ['queue2', 'queue3']);
$this->queueManagement->addMessageToQueues('topic3', 'messageBody3', ['queue1', 'queue3']);
$this->queueManagement->addMessageToQueues('topic4', 'messageBody4', ['queue1', 'queue2', 'queue3']);
$this->queueManagement->addMessageToQueues('topic1', 'messageBody1', ['queue1']);
$this->queueManagement->addMessageToQueues('topic2', 'messageBody2', ['queue1']);
$this->queueManagement->addMessageToQueues('topic3', 'messageBody3', ['queue1']);
$maxMessagesNumber = 2;
$messages = $this->queueManagement->readMessages('queue3', $maxMessagesNumber);
$messages = $this->queueManagement->readMessages('queue1', $maxMessagesNumber);

$this->assertCount($maxMessagesNumber, $messages);

$firstMessage = array_shift($messages);
$this->assertEquals('topic2', $firstMessage[QueueManagement::MESSAGE_TOPIC]);
$this->assertEquals('messageBody2', $firstMessage[QueueManagement::MESSAGE_BODY]);
$this->assertEquals('queue3', $firstMessage[QueueManagement::MESSAGE_QUEUE_NAME]);
$this->assertEquals('topic1', $firstMessage[QueueManagement::MESSAGE_TOPIC]);
$this->assertEquals('messageBody1', $firstMessage[QueueManagement::MESSAGE_BODY]);
$this->assertEquals('queue1', $firstMessage[QueueManagement::MESSAGE_QUEUE_NAME]);
$this->assertEquals(
QueueManagement::MESSAGE_STATUS_IN_PROGRESS,
$firstMessage[QueueManagement::MESSAGE_STATUS]
Expand All @@ -55,9 +55,9 @@ public function testAllFlows()
$this->assertCount(12, date_parse($firstMessage[QueueManagement::MESSAGE_UPDATED_AT]));

$secondMessage = array_shift($messages);
$this->assertEquals('topic3', $secondMessage[QueueManagement::MESSAGE_TOPIC]);
$this->assertEquals('messageBody3', $secondMessage[QueueManagement::MESSAGE_BODY]);
$this->assertEquals('queue3', $secondMessage[QueueManagement::MESSAGE_QUEUE_NAME]);
$this->assertEquals('topic2', $secondMessage[QueueManagement::MESSAGE_TOPIC]);
$this->assertEquals('messageBody2', $secondMessage[QueueManagement::MESSAGE_BODY]);
$this->assertEquals('queue1', $secondMessage[QueueManagement::MESSAGE_QUEUE_NAME]);
$this->assertEquals(
QueueManagement::MESSAGE_STATUS_IN_PROGRESS,
$secondMessage[QueueManagement::MESSAGE_STATUS]
Expand All @@ -67,35 +67,128 @@ public function testAllFlows()
$this->assertTrue(is_numeric($secondMessage[QueueManagement::MESSAGE_QUEUE_RELATION_ID]));
$this->assertEquals(0, $secondMessage[QueueManagement::MESSAGE_NUMBER_OF_TRIALS]);
$this->assertCount(12, date_parse($secondMessage[QueueManagement::MESSAGE_UPDATED_AT]));
}

/**
* @magentoDataFixture Magento/MysqlMq/_files/queues.php
*/
public function testMessageReadingMultipleQueues()
{
$this->queueManagement->addMessageToQueues('topic1', 'messageBody1', ['queue1']);
$this->queueManagement->addMessageToQueues('topic2', 'messageBody2', ['queue1', 'queue2']);
$this->queueManagement->addMessageToQueues('topic3', 'messageBody3', ['queue2']);

$maxMessagesNumber = 2;
$messages = $this->queueManagement->readMessages('queue1', $maxMessagesNumber);
$this->assertCount($maxMessagesNumber, $messages);

$message = array_shift($messages);
$this->assertEquals('topic1', $message[QueueManagement::MESSAGE_TOPIC]);
$this->assertEquals('messageBody1', $message[QueueManagement::MESSAGE_BODY]);
$this->assertEquals('queue1', $message[QueueManagement::MESSAGE_QUEUE_NAME]);
$this->assertEquals(
QueueManagement::MESSAGE_STATUS_IN_PROGRESS,
$message[QueueManagement::MESSAGE_STATUS]
);

$message= array_shift($messages);
$this->assertEquals('topic2', $message[QueueManagement::MESSAGE_TOPIC]);
$this->assertEquals('messageBody2', $message[QueueManagement::MESSAGE_BODY]);
$this->assertEquals('queue1', $message[QueueManagement::MESSAGE_QUEUE_NAME]);
$this->assertEquals(
QueueManagement::MESSAGE_STATUS_IN_PROGRESS,
$message[QueueManagement::MESSAGE_STATUS]
);

$maxMessagesNumber = 2;
$messages = $this->queueManagement->readMessages('queue2', $maxMessagesNumber);
$this->assertCount($maxMessagesNumber, $messages);

$message= array_shift($messages);
$this->assertEquals('topic2', $message[QueueManagement::MESSAGE_TOPIC]);
$this->assertEquals('messageBody2', $message[QueueManagement::MESSAGE_BODY]);
$this->assertEquals('queue2', $message[QueueManagement::MESSAGE_QUEUE_NAME]);
$this->assertEquals(
QueueManagement::MESSAGE_STATUS_IN_PROGRESS,
$message[QueueManagement::MESSAGE_STATUS]
);

$message = array_shift($messages);
$this->assertEquals('topic3', $message[QueueManagement::MESSAGE_TOPIC]);
$this->assertEquals('messageBody3', $message[QueueManagement::MESSAGE_BODY]);
$this->assertEquals('queue2', $message[QueueManagement::MESSAGE_QUEUE_NAME]);
$this->assertEquals(
QueueManagement::MESSAGE_STATUS_IN_PROGRESS,
$message[QueueManagement::MESSAGE_STATUS]
);
}

/**
* @magentoDataFixture Magento/MysqlMq/_files/queues.php
*/
public function testChangingMessageStatus()
{
$this->queueManagement->addMessageToQueues('topic1', 'messageBody1', ['queue1']);
$this->queueManagement->addMessageToQueues('topic2', 'messageBody2', ['queue1']);
$this->queueManagement->addMessageToQueues('topic3', 'messageBody3', ['queue1']);
$this->queueManagement->addMessageToQueues('topic4', 'messageBody4', ['queue1']);

$maxMessagesNumber = 4;
$messages = $this->queueManagement->readMessages('queue1', $maxMessagesNumber);
$this->assertCount($maxMessagesNumber, $messages);

$firstMessage = array_shift($messages);
$secondMessage = array_shift($messages);
$thirdMessage = array_shift($messages);
$fourthMessage = array_shift($messages);

$this->queueManagement->changeStatus(
[
$firstMessage[QueueManagement::MESSAGE_QUEUE_RELATION_ID]
],
QueueManagement::MESSAGE_STATUS_ERROR
);

/** Mark one message as complete or failed and make sure it is not displayed in the list of read messages */
$this->queueManagement->changeStatus(
[
$secondMessage[QueueManagement::MESSAGE_QUEUE_RELATION_ID]
],
QueueManagement::MESSAGE_STATUS_COMPLETE
);
$messages = $this->queueManagement->readMessages('queue3', $maxMessagesNumber);
$this->assertCount(1, $messages);

$this->queueManagement->changeStatus(
[
$firstMessage[QueueManagement::MESSAGE_QUEUE_RELATION_ID]
$thirdMessage[QueueManagement::MESSAGE_QUEUE_RELATION_ID]
],
QueueManagement::MESSAGE_STATUS_ERROR
QueueManagement::MESSAGE_STATUS_NEW
);

$this->queueManagement->changeStatus(
[
$fourthMessage[QueueManagement::MESSAGE_QUEUE_RELATION_ID]
],
QueueManagement::MESSAGE_STATUS_RETRY_REQUIRED
);
$messages = $this->queueManagement->readMessages('queue3', $maxMessagesNumber);
$this->assertCount(0, $messages);

/** Ensure that message for retry is still accessible when reading messages from the queue */
$messages = $this->queueManagement->readMessages('queue2', 1);
$messages = $this->queueManagement->readMessages('queue1');
$this->assertCount(2, $messages);
}

/**
* @magentoDataFixture Magento/MysqlMq/_files/queues.php
*/
public function testMessageRetry()
{
$this->queueManagement->addMessageToQueues('topic1', 'messageBody1', ['queue1']);

$messages = $this->queueManagement->readMessages('queue1', 1);
$message = array_shift($messages);
$messageRelationId = $message[QueueManagement::MESSAGE_QUEUE_RELATION_ID];

for ($i = 0; $i < 2; $i++) {
$this->assertEquals($i, $message[QueueManagement::MESSAGE_NUMBER_OF_TRIALS]);
$this->queueManagement->pushToQueueForRetry($message[QueueManagement::MESSAGE_QUEUE_RELATION_ID]);
$messages = $this->queueManagement->readMessages('queue2', 1);
$messages = $this->queueManagement->readMessages('queue1', 1);
$message = array_shift($messages);
$this->assertEquals($messageRelationId, $message[QueueManagement::MESSAGE_QUEUE_RELATION_ID]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ define([
beforeAll(function (done) {
window.checkoutConfig = {
quoteData: {
entityId: 1
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
entity_Id: 1
},
formKey: 'formKey'
};
Expand Down

0 comments on commit 8ec15ae

Please sign in to comment.