testcontainers / testcontainers/testcontainers-java
Postgres Container with default configuration doesnt work with mapped data binding
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 1.9k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 9
Description
The default configuration for PostgreSQLContainer doesn't work if a non-empty data bind is configured.
For example:
final JdbcDatabaseContainer<?> container = new PostgreSQLContainerProvider().newInstance("13.4");
container.addFileSystemBind("./target/postgres-volume", "/var/lib/postgresql/data", BindMode.READ_WRITE);
container.start();
blocks for 60 seconds until it finally throws an exception because the default WaitStrategy didnt finish within 60 seconds.
This happens because the Log-Output of a Postgres-Container with an existing data-directory doesn't contain the configured log-message twice, but only once.
When configuring the same WaitStrategy expecting the output to be present only once, the startup works as expected:
container.setWaitStrategy(new LogMessageWaitStrategy()
.withRegEx(".*database system is ready to accept connections.*\\s")
.withTimes(1)
.withStartupTimeout(Duration.of(60, SECONDS)));
Proposed Solution:
The default WaitStrategy should first wait for either:
PostgreSQL Database directory appears to contain a database; Skipping initialization
-- or --
.*database system is ready to accept connections.*\s
and after that, wait for:
.*database system is ready to accept connections.*\s
Contributor guide
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
Start at PostgreSQLContainer and its default LogMessageWaitStrategy, then reproduce the issue with PostgreSQLContainerProvider, addFileSystemBind, and a non-empty data directory. Verify startup for both initialized and existing data directories, including the expected log-message sequence and timeout behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, java, postgresql
- Domain
- databases, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100