Skip to content

Commit 3bb97ec

Browse files
committed
Add unit test checking no hanging procs present
This patch adds a simple unit test checking that if a tarantool server failed to start within a certain amount of seconds, test-tun raises a comprehensible exception and kills the server process. Follows up #256 Follows up #276
1 parent 9c2cc2d commit 3bb97ec

8 files changed

+76
-2
lines changed

.luacheckrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
globals = {"box", "_TARANTOOL", "tonumber64", "os"}
1+
globals = {"box", "_TARANTOOL", "tonumber64", "os", "test_run"}
22
ignore = {
33
-- Accessing an undefined field of a global variable <debug>.
44
"143/debug",

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ luacheck:
1515
luacheck --config .luacheckrc .
1616

1717
test_integration:
18-
PYTHONPATH=$(PROJECT_DIR) $(PYTHON) test/test-run.py --force $(TEST_RUN_EXTRA_PARAMS)
18+
PYTHONPATH=$(PROJECT_DIR) $(PYTHON) test/test-run.py --force --exclude unittest $(TEST_RUN_EXTRA_PARAMS)
1919

2020
test_unittest:
2121
$(PYTHON) -m unittest discover test/unittest/

test/unittest/box-cc0544b6afd1.lua

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env tarantool
2+
3+
box.cfg {
4+
listen = os.getenv('LISTEN'),
5+
}
6+
7+
require('console').listen(os.getenv('ADMIN'))

test/unittest/hang.result

Whitespace-only changes.

test/unittest/hang.test.lua

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
test_run = require('test_run').new()
2+
3+
-- This test should hang: we are unable to bootstrap the replica, because it is
4+
-- unable to join the master because of lack of granting user permissions.
5+
test_run:cmd('create server replica with rpl_master=default, script="unittest/replica-7f4d4895ff58.lua"')
6+
test_run:cmd('start server replica')
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env tarantool
2+
3+
box.cfg {
4+
listen = os.getenv('LISTEN'),
5+
replication = os.getenv('MASTER'),
6+
}
7+
8+
require('console').listen(os.getenv('ADMIN'))

test/unittest/suite.ini

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[default]
2+
core = tarantool
3+
description = unit tests
4+
script = box-cc0544b6afd1.lua
5+
use_unix_sockets = True
6+
use_unix_sockets_iproto = True
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import os
2+
import subprocess
3+
import sys
4+
import unittest
5+
6+
7+
class TestTarantoolServer(unittest.TestCase):
8+
def test_tarantool_server_not_hanging(self):
9+
env = os.environ.copy()
10+
env['SERVER_START_TIMEOUT'] = '5'
11+
12+
cmd = [sys.executable, 'test/test-run.py', 'unittest/hang.test.lua']
13+
14+
# File names intentionally have hashes to find exactly these processes
15+
# using 'ps' command.
16+
box_instance = 'box-cc0544b6afd1'
17+
replica_instance = 'replica-7f4d4895ff58'
18+
19+
err_msg_1 = ('[Instance "%s"] Failed to start tarantool '
20+
'instance "%s"' % (box_instance, replica_instance))
21+
err_msg_2 = ('[Instance "%s"] Failed to start within %s seconds'
22+
% (replica_instance, env['SERVER_START_TIMEOUT']))
23+
24+
try:
25+
subprocess.check_output(cmd, env=env, universal_newlines=True)
26+
self.fail("Command `%s` did not return non-zero exit code"
27+
% ' '.join(cmd))
28+
except subprocess.CalledProcessError as exc:
29+
err_obj = exc
30+
31+
self.assertIn(err_msg_1, err_obj.output)
32+
self.assertIn(err_msg_2, err_obj.output)
33+
34+
ps_lines = subprocess.check_output(
35+
['ps', '-o', 'command'], universal_newlines=True
36+
).splitlines()
37+
proc_lines = [line.strip() for line in ps_lines
38+
if 'tarantool %s.lua' % box_instance in line or
39+
'tarantool %s.lua' % replica_instance in line]
40+
41+
self.assertFalse(
42+
proc_lines, 'There are some hanging tarantool processes!'
43+
)
44+
45+
46+
if __name__ == '__main__':
47+
unittest.main()

0 commit comments

Comments
 (0)