Skip to content

getBoundPorts failing in Github Action environment #50

@wilzwert

Description

@wilzwert

I stumbled upon a problem while trying to use a RabbitMQ testcontainer with phpunit in my CI (github action) for a basic Symfony 7.3 project.

I use a GenericContainer :

$container = new GenericContainer(self::RABBITMQ_VERSION)
            ->withExposedPorts(self::RABBITMQ_PORT)  // AMQP port 
            ->withEnvironment(['RABBITMQ_DEFAULT_USER' => 'test', 'RABBITMQ_DEFAULT_PASS' => 'test'])
            ->withWait(new WaitForLog('Server startup complete', false, 30000))
;

The container starts, the WaitForLog strategy does its job, but then the getFirstMappedPort method fails to return a port.
Other testcontainers (PostgreContainer and RedisContainer) work as intended.

I suspect it may have to do with the container being not fully started when the inspect method of the StartedGenericContainer is called, resulting in a cached inspectResponse without container ports data.

As a workaround I created a custom wait strategy which forces new inspection in a loop until ports are actually available, and it actually worked.

Could this be related to the 'Container Startup Reliability' mentioned in this PR #42 ? My issue and solution seem consistent with the temporary fix in this PR (300ms delay added in the getBoundPorts method).

Edit: actually I had to decorate the WaitForLog strategy with my own, so that my custom strategy first awaits for bound ports, then calls the original WaitForLog.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions