@@ -414,8 +414,15 @@ def execute(self, server):
414
414
415
415
416
416
class TarantoolStartError (OSError ):
417
- def __init__ (self , name = None ):
417
+ def __init__ (self , name = None , timeout = None ):
418
418
self .name = name
419
+ self .timeout = timeout
420
+
421
+ def __str__ (self ):
422
+ message = '[Instance "{}"] Failed to start' .format (self .name )
423
+ if self .timeout :
424
+ return "\n {} within {} seconds\n " .format (message , self .timeout )
425
+ return "\n {}\n " .format (message )
419
426
420
427
421
428
class TarantoolLog (object ):
@@ -444,16 +451,18 @@ def seek_once(self, msg):
444
451
if pos != - 1 :
445
452
return pos
446
453
447
- def seek_wait (self , msg , proc = None , name = None ):
448
- while True :
454
+ def seek_wait (self , msg , proc = None , name = None , deadline = None ):
455
+ while not deadline or time . time () < deadline :
449
456
if os .path .exists (self .path ):
450
457
break
451
458
gevent .sleep (0.001 )
459
+ else :
460
+ return False
452
461
453
462
with open (self .path , 'r' ) as f :
454
463
f .seek (self .log_begin , os .SEEK_SET )
455
464
cur_pos = self .log_begin
456
- while True :
465
+ while not deadline or time . time () < deadline :
457
466
if not (proc is None ):
458
467
if not (proc .poll () is None ):
459
468
raise TarantoolStartError (name )
@@ -463,8 +472,9 @@ def seek_wait(self, msg, proc=None, name=None):
463
472
f .seek (cur_pos , os .SEEK_SET )
464
473
continue
465
474
if re .findall (msg , log_str ):
466
- return
475
+ return True
467
476
cur_pos = f .tell ()
477
+ return False
468
478
469
479
470
480
class TarantoolServer (Server ):
@@ -873,9 +883,10 @@ def start(self, silent=True, wait=True, wait_load=True, rais=True, args=[],
873
883
self .crash_detector .start ()
874
884
875
885
if wait :
886
+ deadline = time .time () + Options ().args .server_start_timeout
876
887
try :
877
- self .wait_until_started (wait_load )
878
- except TarantoolStartError :
888
+ self .wait_until_started (wait_load , deadline )
889
+ except TarantoolStartError as err :
879
890
# Python tests expect we raise an exception when non-default
880
891
# server fails
881
892
if self .crash_expected :
@@ -884,9 +895,7 @@ def start(self, silent=True, wait=True, wait_load=True, rais=True, args=[],
884
895
self .current_test .is_crash_reported ):
885
896
if self .current_test :
886
897
self .current_test .is_crash_reported = True
887
- color_stdout ('\n [Instance "{0.name}"] Tarantool server '
888
- 'failed to start\n ' .format (self ),
889
- schema = 'error' )
898
+ color_stdout (err , schema = 'error' )
890
899
self .print_log (15 )
891
900
# Raise exception when caller ask for it (e.g. in case of
892
901
# non-default servers)
@@ -1084,7 +1093,19 @@ def kill_old_server(self, silent=True):
1084
1093
self .wait_until_stopped (pid )
1085
1094
return True
1086
1095
1087
- def wait_until_started (self , wait_load = True ):
1096
+ def wait_load (self , deadline ):
1097
+ """Wait until the server log file is matched the entry pattern
1098
+
1099
+ If the entry pattern couldn't be found in a log file until a timeout
1100
+ is up, it will raise a TarantoolStartError exception.
1101
+ """
1102
+ msg = 'entering the event loop|will retry binding|hot standby mode'
1103
+ p = self .process if not self .gdb and not self .lldb else None
1104
+ if not self .logfile_pos .seek_wait (msg , p , self .name , deadline ):
1105
+ raise TarantoolStartError (
1106
+ self .name , Options ().args .server_start_timeout )
1107
+
1108
+ def wait_until_started (self , wait_load = True , deadline = None ):
1088
1109
""" Wait until server is started.
1089
1110
1090
1111
Server consists of two parts:
@@ -1095,12 +1116,9 @@ def wait_until_started(self, wait_load=True):
1095
1116
color_log ('DEBUG: [Instance {}] Waiting until started '
1096
1117
'(wait_load={})\n ' .format (self .name , str (wait_load )),
1097
1118
schema = 'info' )
1098
-
1099
1119
if wait_load :
1100
- msg = 'entering the event loop|will retry binding|hot standby mode'
1101
- p = self .process if not self .gdb and not self .lldb else None
1102
- self .logfile_pos .seek_wait (msg , p , self .name )
1103
- while True :
1120
+ self .wait_load (deadline )
1121
+ while not deadline or time .time () < deadline :
1104
1122
try :
1105
1123
temp = AdminConnection ('localhost' , self .admin .port )
1106
1124
if not wait_load :
@@ -1126,6 +1144,9 @@ def wait_until_started(self, wait_load=True):
1126
1144
gevent .sleep (0.1 )
1127
1145
continue
1128
1146
raise
1147
+ else :
1148
+ raise TarantoolStartError (
1149
+ self .name , Options ().args .server_start_timeout )
1129
1150
1130
1151
def wait_until_stopped (self , pid ):
1131
1152
while True :
0 commit comments