Tests: fixing tests interrupt in terminal.

KeyboardInterrupt re-raised.
This commit is contained in:
Max Romanov
2020-11-16 20:37:01 +03:00
parent 6d2b60ff3e
commit 567f0a7b30
10 changed files with 52 additions and 9 deletions

View File

@@ -215,7 +215,7 @@ def run(request):
# print unit.log in case of error # print unit.log in case of error
if request.node.rep_call.failed: if hasattr(request.node, 'rep_call') and request.node.rep_call.failed:
_print_log() _print_log()
# remove unit.log # remove unit.log
@@ -284,6 +284,11 @@ def unit_stop():
retcode = p.wait(15) retcode = p.wait(15)
if retcode: if retcode:
return 'Child process terminated with code ' + str(retcode) return 'Child process terminated with code ' + str(retcode)
except KeyboardInterrupt:
p.kill()
raise
except: except:
p.kill() p.kill()
return 'Could not terminate unit' return 'Could not terminate unit'
@@ -403,6 +408,10 @@ def waitforsocket(port):
sock.connect(('127.0.0.1', port)) sock.connect(('127.0.0.1', port))
ret = True ret = True
break break
except KeyboardInterrupt:
raise
except: except:
sock.close() sock.close()
time.sleep(0.1) time.sleep(0.1)

View File

@@ -36,7 +36,7 @@ class TestGoIsolation(TestApplicationGo):
try: try:
nogroup_gid = grp.getgrnam('nogroup').gr_gid nogroup_gid = grp.getgrnam('nogroup').gr_gid
nogroup = 'nogroup' nogroup = 'nogroup'
except: except KeyError:
nogroup_gid = grp.getgrnam('nobody').gr_gid nogroup_gid = grp.getgrnam('nobody').gr_gid
nogroup = 'nobody' nogroup = 'nobody'

View File

@@ -31,8 +31,11 @@ class TestJavaIsolationRootfs(TestApplicationJava):
process.communicate() process.communicate()
except KeyboardInterrupt:
raise
except: except:
pytest.fail('Cann\'t run mount process.') pytest.fail('Can\'t run mount process.')
def teardown_method(self, is_su): def teardown_method(self, is_su):
if not is_su: if not is_su:
@@ -46,8 +49,11 @@ class TestJavaIsolationRootfs(TestApplicationJava):
process.communicate() process.communicate()
except KeyboardInterrupt:
raise
except: except:
pytest.fail('Cann\'t run mount process.') pytest.fail('Can\'t run mount process.')
def test_java_isolation_rootfs_chroot_war(self, is_su, temp_dir): def test_java_isolation_rootfs_chroot_war(self, is_su, temp_dir):
if not is_su: if not is_su:

View File

@@ -730,7 +730,7 @@ last line: 987654321
try: try:
group_id = grp.getgrnam(group).gr_gid group_id = grp.getgrnam(group).gr_gid
except: except KeyError:
group = 'nogroup' group = 'nogroup'
group_id = grp.getgrnam(group).gr_gid group_id = grp.getgrnam(group).gr_gid
@@ -775,7 +775,7 @@ last line: 987654321
try: try:
grp.getgrnam(group) grp.getgrnam(group)
group = True group = True
except: except KeyError:
group = False group = False
if group: if group:

View File

@@ -134,6 +134,9 @@ class TestStatic(TestApplicationProto):
open(temp_dir + 'а', 'a').close() open(temp_dir + 'а', 'a').close()
utf8 = True utf8 = True
except KeyboardInterrupt:
raise
except: except:
utf8 = False utf8 = False

View File

@@ -486,6 +486,10 @@ basicConstraints = critical,CA:TRUE"""
resp = self.get_ssl( resp = self.get_ssl(
headers={'Host': 'localhost', 'Connection': 'close'}, sock=sock headers={'Host': 'localhost', 'Connection': 'close'}, sock=sock
) )
except KeyboardInterrupt:
raise
except: except:
resp = None resp = None

View File

@@ -34,10 +34,16 @@ class TestApplicationGo(TestApplicationProto):
option.test_dir + '/go/' + script + '/' + name + '.go', option.test_dir + '/go/' + script + '/' + name + '.go',
] ]
if option.detailed:
print("\n$ GOPATH=" + env['GOPATH'] + " " + " ".join(args))
try: try:
process = subprocess.Popen(args, env=env) process = subprocess.Popen(args, env=env)
process.communicate() process.communicate()
except KeyboardInterrupt:
raise
except: except:
return None return None

View File

@@ -71,12 +71,18 @@ class TestApplicationJava(TestApplicationProto):
] ]
javac.extend(src) javac.extend(src)
if option.detailed:
print("\n$ " + " ".join(javac))
try: try:
process = subprocess.Popen(javac, stderr=subprocess.STDOUT) process = subprocess.Popen(javac, stderr=subprocess.STDOUT)
process.communicate() process.communicate()
except KeyboardInterrupt:
raise
except: except:
pytest.fail('Cann\'t run javac process.') pytest.fail('Can\'t run javac process.')
def load(self, script, **kwargs): def load(self, script, **kwargs):
self.prepare_env(script) self.prepare_env(script)

View File

@@ -25,5 +25,8 @@ def check_go(current_dir, temp_dir, test_dir):
if process.returncode == 0: if process.returncode == 0:
return True return True
except KeyboardInterrupt:
raise
except: except:
return None return None

View File

@@ -187,6 +187,10 @@ class TestHTTP(TestUnit):
try: try:
part = sock.recv(buff_size) part = sock.recv(buff_size)
except KeyboardInterrupt:
raise
except: except:
break break
@@ -242,7 +246,8 @@ class TestHTTP(TestUnit):
try: try:
last_size = int(chunks[-2], 16) last_size = int(chunks[-2], 16)
except:
except ValueError:
pytest.fail('Invalid zero size chunk') pytest.fail('Invalid zero size chunk')
if last_size != 0 or chunks[-1] != b'': if last_size != 0 or chunks[-1] != b'':
@@ -252,7 +257,8 @@ class TestHTTP(TestUnit):
while len(chunks) >= 2: while len(chunks) >= 2:
try: try:
size = int(chunks.pop(0), 16) size = int(chunks.pop(0), 16)
except:
except ValueError:
pytest.fail('Invalid chunk size %s' % str(size)) pytest.fail('Invalid chunk size %s' % str(size))
if size == 0: if size == 0: