File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed
modules/trino/testcontainers/trino Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -25,14 +25,12 @@ def __init__(
2525 image = "trinodb/trino:latest" ,
2626 user : str = "test" ,
2727 port : int = 8080 ,
28- delay : int = 5 ,
2928 ** kwargs ,
3029 ):
3130 super ().__init__ (image = image , ** kwargs )
3231 self .user = user
3332 self .port = port
3433 self .with_exposed_ports (self .port )
35- self .delay = delay
3634
3735 @wait_container_is_ready ()
3836 def _connect (self ) -> None :
@@ -42,17 +40,21 @@ def _connect(self) -> None:
4240 c .max_tries ,
4341 c .sleep_time ,
4442 )
45- # To avoid `TrinoQueryError(type=INTERNAL_ERROR, name=GENERIC_INTERNAL_ERROR, message="nodes is empty")`
46- time .sleep (self .delay )
4743 conn = connect (
4844 host = self .get_container_host_ip (),
4945 port = self .get_exposed_port (self .port ),
5046 user = self .user ,
5147 )
52- cur = conn .cursor ()
53- cur .execute ("SELECT 1" )
54- cur .fetchall ()
55- conn .close ()
48+ deadline = time .time () + c .max_tries
49+ while time .time () < deadline :
50+ try :
51+ cur = conn .cursor ()
52+ cur .execute ("SELECT * FROM tpch.tiny.nation LIMIT 1" )
53+ cur .fetchall ()
54+ return
55+ except Exception :
56+ time .sleep (c .sleep_time )
57+ raise TimeoutError (f"Trino did not start within { c .max_tries :.3f} seconds" )
5658
5759 def get_connection_url (self ):
5860 return f"trino://{ self .user } @{ self .get_container_host_ip ()} :{ self .port } "
You can’t perform that action at this time.
0 commit comments