Skip to content

Commit 16ff53d

Browse files
committed
Add test_timeout to limit test run time
Added 'test-timeout' option to be able to break the test process with kill signal if the test runs longer than this amount of seconds. By default it is equal to 110 seconds. This value should be bigger than 'replication-sync-timeout' (which is 100 seconds by default) and lower than 'no-output-timeout' (which is 120 seconds by default). This timeout helped to avoid of issues with hanging tests till reach of 'no-output-timeout' timeout, when overall testing exits. For now if the test hangs than 'test-timeout' timeout helps to exit the test processes. It gives the test-run worker chance to restart the failed test either continue tests in worker queue. Before this fix tests, hanged, like [1] and [2], for now the same issues resolved, like [3] and [4] appropriate. To reproduce the issues like [2], try to set 'test-timeout' not enough to complete the test on 'restart server ...' command, like: ./test-run.py replication/quorum.test.lua --test-timeout 5 \ --no-output-timeout 10 --conf memtx The fix resolves the issue #157 together with PR #186, which helps to kill the instances when SIGTERM couldn't do it. Part of #157 [1] - https://gitlab.com/tarantool/tarantool/-/jobs/835734706#L4968 [2] - https://gitlab.com/tarantool/tarantool/-/jobs/822649038#L4835 [3] - https://gitlab.com/tarantool/tarantool/-/jobs/874058059#L4993 [4] - https://gitlab.com/tarantool/tarantool/-/jobs/874058745#L5316
1 parent 08a4817 commit 16ff53d

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

lib/app_server.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
from gevent.subprocess import Popen, PIPE
88

9+
from lib.colorer import color_stdout
910
from lib.colorer import color_log
11+
from lib.options import Options
1012
from lib.preprocessor import TestState
1113
from lib.server import Server
1214
from lib.tarantool_server import Test
@@ -16,12 +18,22 @@
1618
from lib.utils import format_process
1719
from lib.utils import warn_unix_socket
1820
from test import TestRunGreenlet, TestExecutionError
21+
from threading import Timer
22+
23+
24+
def timeout_handler(server_process, test_timeout):
25+
color_stdout("Test timeout of %d secs reached\t" % test_timeout, schema='error')
26+
server_process.kill()
1927

2028

2129
def run_server(execs, cwd, server, logfile, retval):
2230
os.putenv("LISTEN", server.iproto)
2331
server.process = Popen(execs, stdout=PIPE, stderr=PIPE, cwd=cwd)
32+
test_timeout = Options().args.test_timeout
33+
timer = Timer(test_timeout, timeout_handler, [server.process, test_timeout])
34+
timer.start()
2435
stdout, stderr = server.process.communicate()
36+
timer.cancel()
2537
sys.stdout.write(stdout)
2638
with open(logfile, 'a') as f:
2739
f.write(stderr)

lib/options.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ def __init__(self):
190190
Such files created by workers in the "var/reproduce" directory.
191191
Note: The option works now only with parallel testing.""")
192192

193+
parser.add_argument(
194+
"--test-timeout",
195+
dest="test_timeout",
196+
default=110,
197+
type=int,
198+
help="""Break the test process with kill signal if the test runs
199+
longer than this amount of seconds. Default: 110 [seconds].""")
200+
193201
parser.add_argument(
194202
"--no-output-timeout",
195203
dest="no_output_timeout",

lib/tarantool_server.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import yaml
1515

1616
from gevent import socket
17+
from gevent import Timeout
1718
from greenlet import GreenletExit
1819

1920
try:
@@ -24,6 +25,7 @@
2425
from lib.admin_connection import AdminConnection, AdminAsyncConnection
2526
from lib.box_connection import BoxConnection
2627
from lib.colorer import color_stdout, color_log
28+
from lib.options import Options
2729
from lib.preprocessor import TestState
2830
from lib.server import Server
2931
from lib.test import Test
@@ -38,12 +40,15 @@
3840
def save_join(green_obj, timeout=None):
3941
"""
4042
Gevent join wrapper for
41-
test-run stop-on-crash feature
43+
test-run stop-on-crash/stop-on-timeout feature
4244
43-
:return True in case of crash and False otherwise
45+
:return True in case of crash or test timeout and False otherwise
4446
"""
4547
try:
46-
green_obj.join(timeout=timeout)
48+
green_obj.get(timeout=timeout)
49+
except Timeout:
50+
color_stdout("Test timeout of %d secs reached\t" % timeout, schema='error')
51+
return True
4752
except GreenletExit:
4853
return True
4954
# We don't catch TarantoolStartError here to propagate it to a parent
@@ -54,7 +59,6 @@ def save_join(green_obj, timeout=None):
5459
class LuaTest(Test):
5560
""" Handle *.test.lua and *.test.sql test files. """
5661

57-
TIMEOUT = 60 * 10
5862
RESULT_FILE_VERSION_INITIAL = 1
5963
RESULT_FILE_VERSION_DEFAULT = 2
6064
RESULT_FILE_VERSION_LINE_RE = re.compile(
@@ -372,7 +376,7 @@ def execute(self, server):
372376
lua.start()
373377
crash_occured = True
374378
try:
375-
crash_occured = save_join(lua, timeout=self.TIMEOUT)
379+
crash_occured = save_join(lua, timeout=Options().args.test_timeout)
376380
self.killall_servers(server, ts, crash_occured)
377381
except KeyboardInterrupt:
378382
# prevent tests greenlet from writing to the real stdout

0 commit comments

Comments
 (0)