From 663ae64dc22c75d09d6aaf6cac84ad87bd1d3664 Mon Sep 17 00:00:00 2001 From: Gowri Date: Sat, 17 Feb 2024 17:03:23 +1030 Subject: [PATCH] :test_tube: actually run events retry test 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. --- .github/workflows/integration-tests.yml | 3 +++ Test/Integration/EventRetryTest.php | 24 +++++++++++++++--------- Test/_files/ce.php | 9 +++++++++ Test/_files/http_async_events.php | 2 +- 4 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 Test/_files/ce.php diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index dad78c3..a5f5a41 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -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 diff --git a/Test/Integration/EventRetryTest.php b/Test/Integration/EventRetryTest.php index 72a488a..92f01ed 100644 --- a/Test/Integration/EventRetryTest.php +++ b/Test/Integration/EventRetryTest.php @@ -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([ @@ -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() { @@ -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()); @@ -88,7 +92,7 @@ public function testRetry() $e->getMessage() ); } finally { - $this->publisherConsumerController->stopConsumers(); + $publisherConsumerController->stopConsumers(); } $table = $this->connection->getTableName('async_event_subscriber_log'); @@ -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']); } } diff --git a/Test/_files/ce.php b/Test/_files/ce.php new file mode 100644 index 0000000..665a33b --- /dev/null +++ b/Test/_files/ce.php @@ -0,0 +1,9 @@ + \MageOS\AsyncEvents\Test\Integration\TestConfig::class +]; diff --git a/Test/_files/http_async_events.php b/Test/_files/http_async_events.php index fc5896a..1d05bb8 100644 --- a/Test/_files/http_async_events.php +++ b/Test/_files/http_async_events.php @@ -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',