Skip to content

Commit

Permalink
fix(core): Reload container in wait_for_logs before checking status
Browse files Browse the repository at this point in the history
The status is cached on the Model instance. Without the reload, we
always see the first value that was loaded.
  • Loading branch information
mschmitzer committed Oct 17, 2024
1 parent deb6a6a commit 08bf23f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/testcontainers/core/waiting_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def wait_for_logs(
"""
if isinstance(predicate, str):
predicate = re.compile(predicate, re.MULTILINE).search
wrapped = container.get_wrapped_container()
start = time.time()
while True:
duration = time.time() - start
Expand All @@ -121,6 +122,8 @@ def wait_for_logs(
return duration
if duration > timeout:
raise TimeoutError(f"Container did not emit logs satisfying predicate in {timeout:.3f} " "seconds")
if raise_on_exit and container.get_wrapped_container().status not in _NOT_EXITED_STATUSES:
raise RuntimeError("Container exited before emitting logs satisfying predicate")
if raise_on_exit:
wrapped.reload()
if wrapped.status not in _NOT_EXITED_STATUSES:
raise RuntimeError("Container exited before emitting logs satisfying predicate")
time.sleep(interval)

0 comments on commit 08bf23f

Please sign in to comment.