Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to reproduce reuse of AMQP queue between tests #398

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions packages/Amqp/tests/Integration/AmqpMessageChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading