Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the 'timeout' option into 'stop server' command and kill a server… #186

Merged
merged 2 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/colorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,33 @@ def color_log(*args, **kwargs):
color_stdout(*args, **kwargs)


def qa_notice(*args, **kwargs):
""" Print a notice for an QA engineer at the terminal.

Example::

* [QA Notice]
*
* Attempt to stop already stopped server 'foo'
*
"""
# Import from the function to avoid recursive import.
from lib.utils import prefix_each_line

# Use 'info' color by default (yellow).
if 'schema' not in kwargs:
kwargs = dict(kwargs, schema='info')

# Join all positional arguments (like color_stdout() do) and
# decorate with a header and asterisks.
data = ''.join([str(msg) for msg in args])
data = prefix_each_line('* ', data)
data = '\n* [QA Notice]\n*\n{}*\n'.format(data)

# Write out.
color_stdout(data, **kwargs)


class CSchema(object):
objects = {}

Expand Down
4 changes: 2 additions & 2 deletions lib/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from lib.utils import prefix_each_line
from lib.colorer import color_stdout
from lib.colorer import color_log
from lib.colorer import qa_notice

from lib.tarantool_server import TarantoolStartError
from lib.preprocessor import LuaPreprocessorException
Expand Down Expand Up @@ -102,8 +103,7 @@ def handle(self, socket, addr):
# propagate to the main greenlet
raise
except LuaPreprocessorException as e:
color_stdout('\n* [QA Notice]\n*\n* {0}\n*\n'.format(str(e)),
schema='info')
qa_notice(str(e))
result = {'error': str(e)}
except Exception as e:
self.parser.kill_current_test()
Expand Down
22 changes: 21 additions & 1 deletion lib/tarantool_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from gevent import socket
from greenlet import GreenletExit
from threading import Timer

try:
from cStringIO import StringIO
Expand All @@ -23,7 +24,9 @@

from lib.admin_connection import AdminConnection, AdminAsyncConnection
from lib.box_connection import BoxConnection
from lib.colorer import color_stdout, color_log
from lib.colorer import color_stdout
from lib.colorer import color_log
from lib.colorer import qa_notice
from lib.preprocessor import TestState
from lib.server import Server
from lib.test import Test
Expand Down Expand Up @@ -984,9 +987,26 @@ def stop(self, silent=True, signal=signal.SIGTERM):
self.process.send_signal(signal)
except OSError:
pass

# Waiting for stopping the server. If the timeout
# reached, send SIGKILL.
timeout = 5

def kill():
qa_notice('The server \'{}\' does not stop during {} '
'seconds after the {} ({}) signal.\n'
'Info: {}\n'
'Sending SIGKILL...'.format(
self.name, timeout, signal, signame(signal),
format_process(self.process.pid)))
self.process.kill()

timer = Timer(timeout, kill)
timer.start()
if self.crash_detector is not None:
save_join(self.crash_detector)
self.wait_stop()
timer.cancel()

self.status = None
if re.search(r'^/', str(self._admin.port)):
Expand Down