testcontainers / testcontainers/testcontainers-php
getBoundPorts failing in Github Action environment
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 215
- Forks
- 34
- Avg merge
- 1h 59m
- Merged PRs (30d)
- 3
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the GenericContainer RabbitMQ case in a GitHub Actions environment and start with getFirstMappedPort, getBoundPorts, StartedGenericContainer::inspect, and the WaitForLog strategy. Compare the behavior with the temporary fix in PR #42 and verify that bound ports are available before the log wait completes, without requiring a custom wait strategy.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, rabbitmq, symfony
- Domain
- ci-cd, testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100