Skip to content
Snippets Groups Projects
Commit c992d9d9 authored by Konstantin Osipov's avatar Konstantin Osipov
Browse files

Test-runner: a number of changes to improve debugging

When stopping the server under gdb, send SIGTERM
to the server, not to the terminal in which
gdb is started. This gives you the option
to actually examine gdb output before the test
has ended.

When the server crashes, and we're reading
from it in a client connection, detect EOF
and abort reading (the old code was buggy
and would busyloop indefinitely in case of
a crash).

Remove an unnecessary fork() in
start().
parent 42833f73
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,9 @@ class Box(TarantoolConnection):
res = ""
while len(res) < length:
buf = self.socket.recv(length - len(res))
if not buf:
raise RuntimeError("Got EOF from socket, the server has "
"probably crashed")
res = res + buf
return res
......
......@@ -150,12 +150,8 @@ class Server(object):
if self.gdb == True:
raise RuntimeError("'--gdb' and '--start-and-exit' can't be defined together")
pid = os.fork()
if pid > 0:
os.wait()
else:
with daemon.DaemonContext(working_directory = self.vardir):
os.execvp(args[0], args)
with daemon.DaemonContext(working_directory = self.vardir):
os.execvp(args[0], args)
def prepare_args(self):
return [self.binary]
......@@ -188,21 +184,31 @@ class Server(object):
wait_until_connected(self.port)
# Set is_started flag, to nicely support cleanup during an exception.
self.is_started = True
with open(self.pidfile) as f:
self.pid = int(f.read())
def stop(self, silent=True):
"""Stop server instance. Do nothing if the server is not started,
to properly shut down the server in case of an exception during
start up."""
if self.is_started:
if not silent:
print "Stopping the server..."
if self.process == None:
self.kill_old_server()
self.process.terminate()
if not self.is_started:
if not silent:
print "The server is not started."
return
if not silent:
print "Stopping the server..."
if self.process == None:
self.kill_old_server()
else:
self.kill_server()
if self.gdb:
self.process.expect(pexpect.EOF, timeout = 1 << 30)
else:
self.process.expect(pexpect.EOF)
self.is_started = False
elif not silent:
print "The server is not started."
self.is_started = False
self.pid = None
def deploy(self, config=None, binary=None, vardir=None,
mem=None, start_and_exit=None, gdb=None, valgrind=None, silent=True):
......@@ -232,6 +238,14 @@ class Server(object):
stderr = subprocess.STDOUT).stdout.read()
print output
def kill_server(self):
"""Kill a server which was started correctly"""
try:
os.kill(self.pid, signal.SIGTERM)
except OSError as e:
print e
pass
def kill_old_server(self, silent=True):
"""Kill old server instance if it exists."""
if os.access(self.pidfile, os.F_OK) == False:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment