Skip to content

Commit 531934a

Browse files
committed
fix(postgres): Convert postgres to new RunFunctionWaitStrategy
This gets rid of a annoying depcreation warning.
1 parent d882695 commit 531934a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

modules/postgres/testcontainers/postgres/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
from testcontainers.core.generic import DbContainer
1717
from testcontainers.core.utils import raise_for_deprecated_parameter
18-
from testcontainers.core.waiting_utils import wait_container_is_ready
18+
from testcontainers.core.wait_strategies import RunFunctionWaitStrategy
19+
from testcontainers.core.waiting_utils import WaitStrategyTarget
1920

2021
_UNSET = object()
2122

@@ -64,6 +65,7 @@ def __init__(
6465
self.driver = f"+{driver}" if driver else ""
6566

6667
self.with_exposed_ports(self.port)
68+
self.waiting_for(RunFunctionWaitStrategy(_check_postgres_ready))
6769

6870
def _configure(self) -> None:
6971
self.with_env("POSTGRES_USER", self.username)
@@ -87,7 +89,6 @@ def get_connection_url(self, host: Optional[str] = None, driver: Optional[str] =
8789
port=self.port,
8890
)
8991

90-
@wait_container_is_ready()
9192
def _connect(self) -> None:
9293
escaped_single_password = self.password.replace("'", "'\"'\"'")
9394
result = self.exec(
@@ -99,3 +100,11 @@ def _connect(self) -> None:
99100
)
100101
if result.exit_code:
101102
raise ConnectionError("pg_isready is not ready yet")
103+
104+
105+
def _check_postgres_ready(container: WaitStrategyTarget) -> bool:
106+
if not isinstance(container, PostgresContainer):
107+
raise AssertionError("This check can only wait for postgres containers to start up")
108+
# This raises a ConnectionError if not ready yet
109+
container._connect()
110+
return True

0 commit comments

Comments
 (0)