Skip to content

[bundle] Apparently the use case tests have never worked properly. #273

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

Merged
merged 1 commit into from
Nov 20, 2017
Merged
Show file tree
Hide file tree
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
18 changes: 11 additions & 7 deletions pkg/enqueue-bundle/Tests/Functional/App/CustomAppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class CustomAppKernel extends Kernel
{
use MicroKernelTrait;

private $enqueueConfigId;

private $enqueueConfig = [
'client' => [
'prefix' => 'enqueue',
Expand All @@ -25,11 +27,13 @@ class CustomAppKernel extends Kernel

public function setEnqueueConfig(array $config)
{
$fs = new Filesystem();
$fs->remove(sys_get_temp_dir().'/EnqueueBundleCustom/cache');
$fs->mkdir(sys_get_temp_dir().'/EnqueueBundleCustom/cache');

$this->enqueueConfig = array_replace_recursive($this->enqueueConfig, $config);
$this->enqueueConfig['client']['app_name'] = str_replace('.', '', uniqid(true));
$this->enqueueConfigId = md5(json_encode($this->enqueueConfig));

$fs = new Filesystem();
$fs->remove(sys_get_temp_dir().'/EnqueueBundleCustom/cache/'.$this->enqueueConfigId);
$fs->mkdir(sys_get_temp_dir().'/EnqueueBundleCustom/cache/'.$this->enqueueConfigId);
}

/**
Expand All @@ -52,20 +56,20 @@ public function registerBundles()
*/
public function getCacheDir()
{
return sys_get_temp_dir().'/EnqueueBundleCustom/cache';
return sys_get_temp_dir().'/EnqueueBundleCustom/cache/'.$this->enqueueConfigId;
}

/**
* @return string
*/
public function getLogDir()
{
return sys_get_temp_dir().'/EnqueueBundleCustom/cache/logs';
return sys_get_temp_dir().'/EnqueueBundleCustom/cache/logs/'.$this->enqueueConfigId;
}

protected function getContainerClass()
{
return parent::getContainerClass().'Custom';
return parent::getContainerClass().'Custom'.$this->enqueueConfigId;
}

/**
Expand Down
97 changes: 67 additions & 30 deletions pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
use Enqueue\Client\DriverInterface;
use Enqueue\Client\Producer;
use Enqueue\Client\ProducerInterface;
use Enqueue\Stomp\StompDestination;
use Enqueue\Symfony\Client\ConsumeMessagesCommand;
use Enqueue\Symfony\Consumption\ContainerAwareConsumeMessagesCommand;
use Interop\Queue\PsrContext;
use Interop\Queue\PsrMessage;
use Interop\Queue\PsrQueue;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\Kernel;

/**
Expand All @@ -24,6 +27,17 @@ public function setUp()
// parent::setUp();
}

public function tearDown()
{
if (static::$kernel) {
$fs = new Filesystem();
$fs->remove(static::$kernel->getLogDir());
$fs->remove(static::$kernel->getCacheDir());
}

parent::tearDown();
}

public function provideEnqueueConfigs()
{
$baseDir = realpath(__DIR__.'/../../../../');
Expand All @@ -44,7 +58,8 @@ public function provideEnqueueConfigs()
'user' => getenv('SYMFONY__RABBITMQ__USER'),
'pass' => getenv('SYMFONY__RABBITMQ__PASSWORD'),
'vhost' => getenv('SYMFONY__RABBITMQ__VHOST'),
'lazy' => false,
'lazy' => true,
'persisted' => false,
],
],
]];
Expand Down Expand Up @@ -90,15 +105,16 @@ public function provideEnqueueConfigs()
],
]];

yield 'stomp' => [[
yield 'rabbitmq_stomp' => [[
'transport' => [
'default' => 'stomp',
'stomp' => [
'default' => 'rabbitmq_stomp',
'rabbitmq_stomp' => [
'host' => getenv('SYMFONY__RABBITMQ__HOST'),
'port' => getenv('SYMFONY__RABBITMQ__STOMP__PORT'),
'login' => getenv('SYMFONY__RABBITMQ__USER'),
'password' => getenv('SYMFONY__RABBITMQ__PASSWORD'),
'vhost' => getenv('SYMFONY__RABBITMQ__VHOST'),
'management_plugin_installed' => true,
'lazy' => false,
],
],
Expand Down Expand Up @@ -184,12 +200,12 @@ public function provideEnqueueConfigs()
],
]];

yield 'gps' => [[
'transport' => [
'default' => 'gps',
'gps' => [],
],
]];
// yield 'gps' => [[
// 'transport' => [
// 'default' => 'gps',
// 'gps' => [],
// ],
// ]];
}

/**
Expand All @@ -199,16 +215,17 @@ public function testProducerSendsMessage(array $enqueueConfig)
{
$this->customSetUp($enqueueConfig);

$this->getMessageProducer()->sendEvent(TestProcessor::TOPIC, 'test message body');
$expectedBody = __METHOD__.time();

$queue = $this->getPsrContext()->createQueue('enqueue.test');
$this->getMessageProducer()->sendEvent(TestProcessor::TOPIC, $expectedBody);

$consumer = $this->getPsrContext()->createConsumer($queue);
$consumer = $this->getPsrContext()->createConsumer($this->getTestQueue());

$message = $consumer->receive(100);

$this->assertInstanceOf(PsrMessage::class, $message);
$this->assertSame('test message body', $message->getBody());
$consumer->acknowledge($message);

$this->assertSame($expectedBody, $message->getBody());
}

/**
Expand All @@ -222,11 +239,10 @@ public function testProducerSendsCommandMessage(array $enqueueConfig)

$this->getMessageProducer()->sendCommand(TestCommandProcessor::COMMAND, $expectedBody);

$queue = $this->getPsrContext()->createQueue('enqueue.test');

$consumer = $this->getPsrContext()->createConsumer($queue);
$consumer = $this->getPsrContext()->createConsumer($this->getTestQueue());

$message = $consumer->receive(100);
$this->assertInstanceOf(PsrMessage::class, $message);
$consumer->acknowledge($message);

$this->assertInstanceOf(PsrMessage::class, $message);
Expand Down Expand Up @@ -265,10 +281,12 @@ public function testClientConsumeMessagesFromExplicitlySetQueue(array $enqueueCo
{
$this->customSetUp($enqueueConfig);

$expectedBody = __METHOD__.time();

$command = $this->container->get(ConsumeMessagesCommand::class);
$processor = $this->container->get('test.message.processor');

$this->getMessageProducer()->sendEvent(TestProcessor::TOPIC, 'test message body');
$this->getMessageProducer()->sendEvent(TestProcessor::TOPIC, $expectedBody);

$tester = new CommandTester($command);
$tester->execute([
Expand All @@ -278,7 +296,7 @@ public function testClientConsumeMessagesFromExplicitlySetQueue(array $enqueueCo
]);

$this->assertInstanceOf(PsrMessage::class, $processor->message);
$this->assertEquals('test message body', $processor->message->getBody());
$this->assertEquals($expectedBody, $processor->message->getBody());
}

/**
Expand All @@ -288,22 +306,31 @@ public function testTransportConsumeMessagesCommandShouldConsumeMessage(array $e
{
$this->customSetUp($enqueueConfig);

if ($this->getTestQueue() instanceof StompDestination) {
$this->markTestSkipped('The test fails with the exception Stomp\Exception\ErrorFrameException: Error "precondition_failed". '.
'It happens because of the destination options are different from the one used while creating the dest. Nothing to do about it'
);
}

$expectedBody = __METHOD__.time();

$command = $this->container->get(ContainerAwareConsumeMessagesCommand::class);
$command->setContainer($this->container);
$processor = $this->container->get('test.message.processor');

$this->getMessageProducer()->sendEvent(TestProcessor::TOPIC, 'test message body');
$this->getMessageProducer()->sendEvent(TestProcessor::TOPIC, $expectedBody);

$tester = new CommandTester($command);
$tester->execute([
'--message-limit' => 1,
'--time-limit' => '+10sec',
'--queue' => ['enqueue.test'],
'--receive-timeout' => 1000,
'--queue' => [$this->getTestQueue()->getQueueName()],
'processor-service' => 'test.message.processor',
]);

$this->assertInstanceOf(PsrMessage::class, $processor->message);
$this->assertEquals('test message body', $processor->message->getBody());
$this->assertEquals($expectedBody, $processor->message->getBody());
}

/**
Expand All @@ -329,16 +356,26 @@ protected function customSetUp(array $enqueueConfig)
$driver = $this->container->get('enqueue.client.driver');
$context = $this->getPsrContext();

$queue = $driver->createQueue('test');

//guard
$this->assertEquals('enqueue.test', $queue->getQueueName());
$driver->setupBroker();

if (method_exists($context, 'deleteQueue')) {
$context->deleteQueue($queue);
try {
if (method_exists($context, 'purgeQueue')) {
$queue = $this->getTestQueue();
$context->purgeQueue($queue);
}
} catch (\Exception $e) {
}
}

$driver->setupBroker();
/**
* @return PsrQueue
*/
protected function getTestQueue()
{
/** @var DriverInterface $driver */
$driver = $this->container->get('enqueue.client.driver');

return $driver->createQueue('test');
}

/**
Expand Down
12 changes: 11 additions & 1 deletion pkg/sqs/SqsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,22 @@ public function deleteQueue(SqsDestination $dest)
}

/**
* @deprecated since 0.8 will be removed 0.9 use self::purgeQueue()
*
* @param SqsDestination $dest
*/
public function purge(SqsDestination $dest)
{
$this->purgeQueue($dest);
}

/**
* @param SqsDestination $destination
*/
public function purgeQueue(SqsDestination $destination)
{
$this->getClient()->purgeQueue([
'QueueUrl' => $this->getQueueUrl($dest),
'QueueUrl' => $this->getQueueUrl($destination),
]);
}
}
2 changes: 1 addition & 1 deletion pkg/stomp/StompConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function createContext()
});
}

return new StompContext($this->stomp);
return new StompContext($this->establishConnection());
}

/**
Expand Down