From 214c2064dc45512b2af3e39e5c714f331ede3ac8 Mon Sep 17 00:00:00 2001 From: Serg Lifinsky Date: Wed, 23 Oct 2024 17:58:46 +0300 Subject: [PATCH] Add test to reproduce reuse of AMQP queue between tests --- .../Integration/AmqpMessageChannelTest.php | 40 +++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/packages/Amqp/tests/Integration/AmqpMessageChannelTest.php b/packages/Amqp/tests/Integration/AmqpMessageChannelTest.php index cbd6bd7e6..d216d19a2 100644 --- a/packages/Amqp/tests/Integration/AmqpMessageChannelTest.php +++ b/packages/Amqp/tests/Integration/AmqpMessageChannelTest.php @@ -121,17 +121,51 @@ public function test_using_amqp_channel_with_custom_queue_name() /** Message should be waiting in the queue */ $this->assertEquals([], $ecotoneLite->getQueryBus()->sendWithRouting('order.getOrders')); - $ecotoneLite->run('orders', ExecutionPollingMetadata::createWithDefaults()->withTestingSetup()); - /** Message should cosumed from the queue */ + $ecotoneLite->run($channelName, ExecutionPollingMetadata::createWithDefaults()->withTestingSetup()); + /** Message should be consumed from the queue */ $this->assertEquals(['milk'], $ecotoneLite->getQueryBus()->sendWithRouting('order.getOrders')); - $ecotoneLite->run('orders', ExecutionPollingMetadata::createWithDefaults()->withTestingSetup()); + $ecotoneLite->run($channelName, ExecutionPollingMetadata::createWithDefaults()->withTestingSetup()); /** Nothing should change, as we have not sent any new command message */ $this->assertEquals(['milk'], $ecotoneLite->getQueryBus()->sendWithRouting('order.getOrders')); $this->getRabbitConnectionFactory()->createContext()->purgeQueue(new AmqpQueue($queueName)); } + /** + * @depends test_using_amqp_channel_with_custom_queue_name + */ + public function test_using_amqp_channel_with_duplicated_queue_name() + { + $channelName = 'orders'; + $queueName = 'orders_queue'; + $this->getRabbitConnectionFactory()->createContext()->purgeQueue(new AmqpQueue($queueName)); + + $ecotoneLite = EcotoneLite::bootstrapForTesting( + [OrderService::class], + [ + new OrderService(), + AmqpConnectionFactory::class => $this->getCachedConnectionFactory(), + ], + ServiceConfiguration::createWithDefaults() + ->withSkippedModulePackageNames(ModulePackageList::allPackagesExcept([ModulePackageList::AMQP_PACKAGE, ModulePackageList::ASYNCHRONOUS_PACKAGE])) + ->withExtensionObjects([ + AmqpBackedMessageChannelBuilder::create( + channelName: $channelName, + queueName: $queueName, + ), + ]) + ); + + $ecotoneLite->getCommandBus()->sendWithRouting('order.register', 'milk'); + + $ecotoneLite->run($channelName, ExecutionPollingMetadata::createWithDefaults()->withTestingSetup()); + /** Message should be consumed from the queue */ + $this->assertEquals(['milk'], $ecotoneLite->getQueryBus()->sendWithRouting('order.getOrders')); + + $this->getRabbitConnectionFactory()->createContext()->purgeQueue(new AmqpQueue($queueName)); + } + public function test_failing_to_receive_message_when_not_declared() { $queueName = Uuid::uuid4()->toString();