Skip to content

[BUG] Cannot run Integration tests that relies on RabbitMQ #117

@gowrizrh

Description

@gowrizrh

🐛 Bug report

Current Behavior

Unable to run RabbitMQ integration tests that rely on RabbitMQ.
This is because the GitHub Action specifies the RabbitMQ docker images without the management plugin. However, the test helper actually relies on the RabbitMQ management APIs.

// \Magento\TestFramework\Helper\Amqp

public function __construct(
    \Magento\Framework\App\DeploymentConfig $deploymentConfig = null
) {
// snip
    $this->host = sprintf(
        '%s://%s:%s/api/',
        defined('RABBITMQ_MANAGEMENT_PROTOCOL')
            ? RABBITMQ_MANAGEMENT_PROTOCOL
            : self::DEFAULT_MANAGEMENT_PROTOCOL,
        $this->deploymentConfig->get(self::CONFIG_PATH_HOST),
        defined('RABBITMQ_MANAGEMENT_PORT') ? RABBITMQ_MANAGEMENT_PORT : self::DEFAULT_MANAGEMENT_PORT
    );
// snip
}

An example error when running a test without the RabbitMQ management plugin.

There was 1 error:

1) Aligent\AsyncEvents\Test\Integration\FailoverTopologyTest::testDelayQueueCreation
Exception: Recv failure: Connection reset by peer

Expected Behavior

Successfully run tests that rely on RabbitMQ.

Minimal reproduction of the problem with instructions

  1. Use the integration test GitHub action
  2. Write an example integration test that relies on RabbitMQ (example below)
class ItWorks extends TestCase
{

    /**
     * @var Amqp|null
     */
    private ?Amqp $helper;

    /**
     * @var RetryManager|null
     */
    private ?RetryManager $retryManager;

    protected function setUp(): void
    {
        $this->helper = Bootstrap::getObjectManager()->create(Amqp::class);
        $this->retryManager = Bootstrap::getObjectManager()->create(RetryManager::class);

        if (!$this->helper->isAvailable()) {
            $this->fail('This test relies on RabbitMQ Management Plugin.');
        }
    }

    public function testDelayQueueCreation(): void
    {
        $exchanges = $this->helper->getExchanges();
        $this->assertArrayHasKey('event.failover', $exchanges);
        $this->assertTrue(true);
    }
}

What is the motivation / use case for changing the behavior?

Modules or features that rely on RabbitMQ as the message broker cannot have integration tests. This action seems to already support it but there's a minor bug.

The simple solution is to use the RabbitMQ images with the management plugin enabled. I'm happy to open a PR for this.

Environment


Magento version: 2.4.5-p1 
PHP Version version: 8.1 


Others:

include:
  - magento: magento/project-community-edition:>=2.4.5 <2.4.6
    php: 8.1
    composer: 2
    mysql: "mysql:8.0"
    elasticsearch: "elasticsearch:7.16.3"
    rabbitmq: "rabbitmq:3.9"
    redis: "redis:6.2"
    varnish: "varnish:7.0"
    nginx: "nginx:1.18"

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions