Skip to content

Commit c2a8b53

Browse files
committed
Add timeout for starting tarantool server
Function wait_until_started in TarantoolServer contains seek_wait, which waits pattern in logfile. If there is no pattern, server is hanging. Was added start-server-time (by default equals to 90 secs). The pattern is sought until the time runs out and wait_until_started returns True if the pattern was found (else False) and TarantoolServer.start() returns same. Was added new logging that the instance wasn't started. Fixes: #276
1 parent 863f1fa commit c2a8b53

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

lib/options.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ def __init__(self):
211211
help="""Break the test process with kill signal if the test runs
212212
longer than this amount of seconds. Default: 110 [seconds].""")
213213

214+
parser.add_argument(
215+
"--server-start-timeout",
216+
dest="server_start_timeout",
217+
default=env_int('SERVER_START_TIMEOUT', 90),
218+
type=int,
219+
help="""Break the test process with kill signal if the test starts
220+
longer than this amount of seconds. Default: 90 [seconds].""")
221+
214222
parser.add_argument(
215223
"--no-output-timeout",
216224
dest="no_output_timeout",

lib/preprocessor.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import yaml
88
from gevent import socket
99

10+
from lib import Options
1011
from lib.admin_connection import AdminAsyncConnection
1112
from lib.colorer import color_log
1213
from lib.utils import signum
@@ -206,8 +207,13 @@ def server_start(self, ctype, sname, opts):
206207
if crash_expected:
207208
# disable crash detector
208209
self.servers[sname].crash_expected = True
209-
self.servers[sname].start(silent=True, rais=True, wait=wait,
210-
wait_load=wait_load, args=args)
210+
if not self.servers[sname].start(
211+
silent=True, rais=True, wait=wait,
212+
wait_load=wait_load, args=args,
213+
server_start_timeout=Options().args.server_start_timeout):
214+
color_log('\n[Instance "{0}"] Failed to start tarantool '
215+
'instance\n'.format(sname),
216+
schema='error')
211217
except Exception as e:
212218
crash_occured = True
213219
if not (crash_expected and

lib/tarantool_server.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ def seek_once(self, msg):
445445
if pos != -1:
446446
return pos
447447

448-
def seek_wait(self, msg, proc=None, name=None):
448+
def seek_wait(self, msg, proc=None, name=None, timeout=90):
449449
while True:
450450
if os.path.exists(self.path):
451451
break
@@ -454,7 +454,8 @@ def seek_wait(self, msg, proc=None, name=None):
454454
with open(self.path, 'r') as f:
455455
f.seek(self.log_begin, os.SEEK_SET)
456456
cur_pos = self.log_begin
457-
while True:
457+
current_time = time.time()
458+
while current_time + timeout > time.time():
458459
if not (proc is None):
459460
if not (proc.poll() is None):
460461
raise TarantoolStartError(name)
@@ -464,8 +465,9 @@ def seek_wait(self, msg, proc=None, name=None):
464465
f.seek(cur_pos, os.SEEK_SET)
465466
continue
466467
if re.findall(msg, log_str):
467-
return
468+
return True
468469
cur_pos = f.tell()
470+
return False
469471

470472

471473
class TarantoolServer(Server):
@@ -756,7 +758,8 @@ def install(self, silent=True):
756758

757759
def deploy(self, silent=True, **kwargs):
758760
self.install(silent)
759-
self.start(silent=silent, **kwargs)
761+
if not self.start(silent=silent, **kwargs):
762+
return False
760763

761764
def copy_files(self):
762765
if self.script:
@@ -829,7 +832,7 @@ def cleanup(self, *args, **kwargs):
829832
*args, **kwargs)
830833

831834
def start(self, silent=True, wait=True, wait_load=True, rais=True, args=[],
832-
**kwargs):
835+
server_start_timeout=90, **kwargs):
833836
if self._start_against_running:
834837
return
835838
if self.status == 'started':
@@ -880,7 +883,9 @@ def start(self, silent=True, wait=True, wait_load=True, rais=True, args=[],
880883

881884
if wait:
882885
try:
883-
self.wait_until_started(wait_load)
886+
if not self.wait_until_started(
887+
wait_load, server_start_timeout=server_start_timeout):
888+
return False
884889
except TarantoolStartError:
885890
# Python tests expect we raise an exception when non-default
886891
# server fails
@@ -1090,22 +1095,26 @@ def kill_old_server(self, silent=True):
10901095
self.wait_until_stopped(pid)
10911096
return True
10921097

1093-
def wait_until_started(self, wait_load=True):
1098+
def wait_until_started(self, wait_load=True, server_start_timeout=90):
10941099
""" Wait until server is started.
10951100
10961101
Server consists of two parts:
10971102
1) wait until server is listening on sockets
10981103
2) wait until server tells us his status
10991104
11001105
"""
1101-
color_log('DEBUG: [Instance {}] Waiting until started '
1102-
'(wait_load={})\n'.format(self.name, str(wait_load)),
1103-
schema='info')
1106+
color_log(
1107+
'DEBUG: [Instance {}] Waiting until started '
1108+
'(wait_load={}, start_timeout={})\n'.format(
1109+
self.name, str(wait_load), str(server_start_timeout)),
1110+
schema='info')
11041111

11051112
if wait_load:
11061113
msg = 'entering the event loop|will retry binding|hot standby mode'
11071114
p = self.process if not self.gdb and not self.lldb else None
1108-
self.logfile_pos.seek_wait(msg, p, self.name)
1115+
if not self.logfile_pos.seek_wait(
1116+
msg, p, self.name, server_start_timeout):
1117+
return False
11091118
while True:
11101119
try:
11111120
temp = AdminConnection('localhost', self.admin.port)

0 commit comments

Comments
 (0)