Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions core/testcontainers/core/waiting_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
return condition()


_NOT_EXITED_STATUSES = {"running", "created"}


def wait_for_logs(
container: "DockerContainer",
predicate: Union[Callable, str],
Expand All @@ -103,11 +106,13 @@
"""
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
stdout = container.get_logs()[0].decode()
stderr = container.get_logs()[1].decode()
stdout, stderr = container.get_logs()
stdout = stdout.decode()
stderr = stderr.decode()
predicate_result = (
predicate(stdout) or predicate(stderr)
if predicate_streams_and is False
Expand All @@ -118,6 +123,8 @@
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 != "running":
raise RuntimeError("Container exited before emitting logs satisfying predicate")
if raise_on_exit:
wrapped.reload()

Check warning on line 127 in core/testcontainers/core/waiting_utils.py

View check run for this annotation

Codecov / codecov/patch

core/testcontainers/core/waiting_utils.py#L127

Added line #L127 was not covered by tests
if wrapped.status not in _NOT_EXITED_STATUSES:
raise RuntimeError("Container exited before emitting logs satisfying predicate")

Check warning on line 129 in core/testcontainers/core/waiting_utils.py

View check run for this annotation

Codecov / codecov/patch

core/testcontainers/core/waiting_utils.py#L129

Added line #L129 was not covered by tests
time.sleep(interval)