feat: Add ExecWaitStrategy and migrate Postgres from deprecated decorator #935
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The
PostgresContainercurrently uses the deprecated@wait_container_is_ready()decorator, which is slated for removal. The container was previously migrated away from log-based waiting due tolocale-dependent issues (#703, #695), but still relies on the deprecated decorator pattern.
Solution
This PR introduces a new
ExecWaitStrategywait strategy and migratesPostgresContainerto use it.Changes
New
ExecWaitStrategyincore/testcontainers/core/wait_strategies.pyDockerContainerwith CLI-based health checksCompositeWaitStrategyexec()Updated
modules/postgres/testcontainers/postgres/__init__.py_connect()method from@wait_container_is_readydecorator toExecWaitStrategypsqlcommand execution to verify database readinessDesign Consideration: Protocol Limitations
Issue: The
WaitStrategyTargetprotocol is designed to support bothDockerContainerandComposeContainer, butExecWaitStrategyonly works withDockerContainer(which has anexec()method).
Current Solution: Runtime check with
hasattr(container, "exec")that raises a clear error if used with incompatible containers.Discussion Points:
ExecWaitStrategyaccept a more specific type (e.g.,DockerContainerdirectly)?I've opted for the runtime check to maintain consistency with the existing
WaitStrategyTargetprotocol pattern, but I'm open to alternatives if the maintainers prefer a different approach.PR Checklist
as we make use of this for detecting Semantic Versioning changes.
all community features will be tagged community-feat,
but we do not want to release minor or major versions due to features or breaking changes outside of core.
So please use
fix(postgres):orfix(my_new_vector_db):if you want to add or modify community modules.This may change in the future if we have a separate package released with community modules.
modules/*(if unsure, look at other existing community modules)
testcontainers.<modulename>.*and you DO NOT have an
__init__.pyabove your module's level.modules/*/testsREADME.rstand hooks in the.. auto-classand.. titleof your container__init__.py) and corresponding tests.pyproject.tomltool.poetry.packages- see other community modulestool.poetry.extraswith the same name as your module name,we still prefer adding NO EXTRA DEPENDENCIES, meaning
mymodule = []is the preferred addition(see the notes at the bottom)
git rebase)