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 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 modules/trino/testcontainers/trino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import re
import time

from testcontainers.core.config import testcontainers_config as c
from testcontainers.core.generic import DbContainer
Expand Down Expand Up @@ -44,10 +45,16 @@ def _connect(self) -> None:
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