Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(trino): add delay time to avoid Trino issue #735

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
feat(trino): use waiting tpch instead of sleep delay time
  • Loading branch information
grieve54706 committed Nov 19, 2024
commit 622d00a5d7138dda0e14bc38db57e8dc99ee433c
18 changes: 10 additions & 8 deletions modules/trino/testcontainers/trino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ def __init__(
image="trinodb/trino:latest",
user: str = "test",
port: int = 8080,
delay: int = 5,
**kwargs,
):
super().__init__(image=image, **kwargs)
self.user = user
self.port = port
self.with_exposed_ports(self.port)
self.delay = delay

@wait_container_is_ready()
def _connect(self) -> None:
Expand All @@ -42,17 +40,21 @@ def _connect(self) -> None:
c.max_tries,
c.sleep_time,
)
# To avoid `TrinoQueryError(type=INTERNAL_ERROR, name=GENERIC_INTERNAL_ERROR, message="nodes is empty")`
time.sleep(self.delay)
conn = connect(
host=self.get_container_host_ip(),
port=self.get_exposed_port(self.port),
user=self.user,
)
cur = conn.cursor()
cur.execute("SELECT 1")
cur.fetchall()
conn.close()
deadline = time.time() + c.max_tries
while time.time() < deadline:
try:
cur = conn.cursor()
cur.execute("SELECT * FROM tpch.tiny.nation LIMIT 1")
cur.fetchall()
return
except Exception:
time.sleep(c.sleep_time)
raise TimeoutError(f"Trino did not start within {c.max_tries:.3f} seconds")

def get_connection_url(self):
return f"trino://{self.user}@{self.get_container_host_ip()}:{self.port}"
Expand Down