Skip to content

Commit 3949ffa

Browse files
pmorchalexanderankin
authored andcommitted
fix(core): Use WaitStrategy internally for wait_for function
Refactor the deprecated wait_for function to use the new WaitStrategy system internally instead of the @wait_container_is_ready decorator. The decorator emitted a deprecation warning at decoration time (import time), causing warnings even when users never called wait_for. Replace with an internal CallableWaitStrategy that uses WaitStrategy._poll() for retry logic. This follows the intended migration path to the new system. Fixes #874
1 parent 183e1aa commit 3949ffa

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

core/testcontainers/core/waiting_utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ def wrapper(wrapped: Callable[..., Any], instance: Any, args: tuple[Any], kwargs
216216
return cast("Callable[[F], F]", wrapper)
217217

218218

219-
@wait_container_is_ready()
220219
def wait_for(condition: Callable[..., bool]) -> bool:
221220
warnings.warn(
222221
"The wait_for function is deprecated and will be removed in a future version. "
@@ -226,7 +225,15 @@ def wait_for(condition: Callable[..., bool]) -> bool:
226225
DeprecationWarning,
227226
stacklevel=2,
228227
)
229-
return condition()
228+
229+
class CallableWaitStrategy(WaitStrategy):
230+
def wait_until_ready(self, container: WaitStrategyTarget) -> None:
231+
pass # Required by ABC, but unused
232+
233+
strategy = CallableWaitStrategy()
234+
if not strategy._poll(condition):
235+
raise TimeoutError(f"Condition not satisfied within {strategy._startup_timeout}s")
236+
return True
230237

231238

232239
_NOT_EXITED_STATUSES = {"running", "created"}

0 commit comments

Comments
 (0)