@@ -152,31 +152,56 @@ def _check_kamel_output(self,
152152 end_condition ,
153153 with_output = False ,
154154 with_timeout = False ):
155- # Implicit 30s timer.
156- countdown = None
155+ # Implicit 2 minute timout in hundredths of a second:
156+ timout_duration = 2 * 60 * 100
157157 if with_timeout :
158- countdown = 30
158+ countdown = timout_duration
159+ reading_thread = utils .LogThread (self .process .stdout )
160+
161+ # Kill thread when program ends in case it does not end before
162+ # that.
163+ reading_thread .daemon = True
164+
165+ # Start thread analyzing logs:
166+ reading_thread .start ()
167+
168+ success = False
159169 while True :
160170 # Log progress of kamel subprocess:
161- output = utils .print_log_from_subprocess (self .subprocess_name ,
162- self .process .stdout ,
163- with_output = with_output )
171+ if with_timeout :
172+ output = utils .print_log_from_queue (self .subprocess_name ,
173+ reading_thread .queue ,
174+ with_output )
175+ else :
176+ output = utils .print_log_from_subprocess (
177+ self .subprocess_name , self .process .stdout , with_output )
164178
165179 # Use the Kamel output to decide when Kamel instance is
166180 # ready to receive requests.
167- if end_condition in output :
168- return True
181+ if output is not None :
182+ if with_timeout :
183+ countdown = timout_duration
184+ if end_condition in output :
185+ success = True
186+ break
169187
170188 # Check process has not exited prematurely.
171189 if self .process .poll () is not None :
172190 break
191+
192+ # If timeout is enabled we decrement countdown.
173193 if with_timeout :
174194 countdown -= 1
175195 if countdown == 0 :
176- return False
177- time .sleep (1 )
196+ break
197+ time .sleep (0.01 )
178198
179- return False
199+ # Terminate log thread:
200+ if with_timeout :
201+ reading_thread .stop_flag .set ()
202+ reading_thread .join ()
203+
204+ return success
180205
181206
182207#
@@ -240,8 +265,7 @@ def pod_is_running(self, integration_name):
240265 # for.
241266 # There should only be one new pod.
242267 output = utils .print_log_from_subprocess (self .subprocess_name ,
243- self .process .stdout ,
244- with_output = True )
268+ self .process .stdout , True )
245269 if self .pod_name == "" :
246270 self .pod_name = kubernetes_utils .extract_pod_name (
247271 output , integration_name )
@@ -277,7 +301,7 @@ def _check_kubectl_output(self,
277301 while True :
278302 output = utils .print_log_from_subprocess (self .subprocess_name ,
279303 self .process .stdout ,
280- with_output = with_output )
304+ with_output )
281305 if self .subcommand_type == \
282306 kubernetes_utils .KubectlCommand .GET_SERVICES :
283307 if kubernetes_utils .service_name_matches (output , service_name ):
@@ -320,8 +344,7 @@ def _check_kafka_output(self, checked_topic):
320344 while True :
321345 # Log progress of kafka topic creation subprocess:
322346 output = utils .print_log_from_subprocess (self .subprocess_name ,
323- self .process .stdout ,
324- with_output = True )
347+ self .process .stdout , True )
325348 if checked_topic is not None and checked_topic in output :
326349 return True
327350
0 commit comments