Skip to content

Commit

Permalink
🧪 actually run events retry test
Browse files Browse the repository at this point in the history
the test had been silently failing in the background
because the queue consumer started did not have
the di preference overriden for Config to TestConfig.

because that always happened in a separate process, it
never came to light that we weren't actually asserting
that retries had been performed in the background.
  • Loading branch information
gowrizrh committed Feb 17, 2024
1 parent 629cae4 commit 663ae64
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ jobs:
sed -i "s/'db-password' => '123123q'/'db-password' => 'password'/" etc/install-config-mysql.php.dist
sed -i "s/'elasticsearch-host' => 'localhost'/'elasticsearch-host' => '127.0.0.1'/" etc/install-config-mysql.php.dist
sed -i "s/'amqp-host' => 'localhost'/'amqp-host' => '127.0.0.1'/" etc/install-config-mysql.php.dist
sed -i "s/'consumers-wait-for-messages' => '0'/'consumers-wait-for-messages' => '1'/" etc/install-config-mysql.php.dist
mkdir etc/di/preferences/cli
cp ../../../vendor/mage-os/mageos-async-events/Test/_files/ce.php ./etc/di/preferences/cli
- run: ../../../vendor/bin/phpunit ../../../vendor/mage-os/mageos-async-events/Test/Integration
working-directory: ../magento2/dev/tests/integration
Expand Down
24 changes: 15 additions & 9 deletions Test/Integration/EventRetryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class EventRetryTest extends TestCase
/** @var PublisherInterface|null */
private ?PublisherInterface $publisher;

/** @var PublisherConsumerController|null */
private ?PublisherConsumerController $publisherConsumerController;

/** @var Json|null */
private ?Json $json;

/** @var ResourceConnection|null */
private ?ResourceConnection $connection;

protected function setUp(): void
{
Bootstrap::getObjectManager()->configure([
Expand All @@ -54,7 +54,6 @@ protected function setUp(): void
*
* @magentoDataFixture MageOS_AsyncEvents::Test/_files/http_async_events.php
* @magentoDbIsolation disabled
* @magentoConfigFixture default/system/async_events/max_deaths 3
*/
public function testRetry()
{
Expand All @@ -68,18 +67,23 @@ public function testRetry()
]
);

$this->publisherConsumerController = Bootstrap::getObjectManager()->create(
$consumerInitParams = Bootstrap::getInstance()->getAppInitParams();

$consumerInitParams['TESTS_BASE_DIR'] = INTEGRATION_TESTS_DIR;
$consumerInitParams['INTEGRATION_TESTS_CLI_AUTOLOADER'] = INTEGRATION_TESTS_DIR . '/framework/autoload.php';

$publisherConsumerController = Bootstrap::getObjectManager()->create(
PublisherConsumerController::class,
[
'consumers' => ['event.trigger.consumer', 'event.retry.consumer'],
'logFilePath' => TESTS_TEMP_DIR . "/MessageQueueTestLog.txt",
'maxMessages' => 10,
'appInitParams' => Bootstrap::getInstance()->getAppInitParams()
'appInitParams' => $consumerInitParams
]
);

try {
$this->publisherConsumerController->startConsumers();
$publisherConsumerController->startConsumers();
sleep(16);
} catch (EnvironmentPreconditionException $e) {
$this->markTestSkipped($e->getMessage());
Expand All @@ -88,7 +92,7 @@ public function testRetry()
$e->getMessage()
);
} finally {
$this->publisherConsumerController->stopConsumers();
$publisherConsumerController->stopConsumers();
}

$table = $this->connection->getTableName('async_event_subscriber_log');
Expand All @@ -100,8 +104,10 @@ public function testRetry()

$events = $connection->fetchAll($select);

$this->assertNotEmpty($events);

foreach ($events as $event) {
// An uuid batch should be retired for 3 times after the first attempt. 1 + 3
// A batch should be retired for 3 times after the first attempt. 1 + 3
$this->assertEquals(4, $event['events']);
}
}
Expand Down
9 changes: 9 additions & 0 deletions Test/_files/ce.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

/**
* Swap out Config for TestConfig during queue consumer run so `example.event` is available in Integration tests.
*/

return [
\MageOS\AsyncEvents\Model\Config::class => \MageOS\AsyncEvents\Test\Integration\TestConfig::class
];
2 changes: 1 addition & 1 deletion Test/_files/http_async_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
$connection->insertOnDuplicate('async_event_subscriber', [
'subscription_id' => 1,
'event_name' => 'example.event',
'recipient_url' => 'https://mock.codes/500',
'recipient_url' => 'https://mock.codes/503',
'status' => 1,
'metadata' => 'http',
'verification_token' => 'secret',
Expand Down

0 comments on commit 663ae64

Please sign in to comment.