From 1297e8a16a2fb0ccc195c0dd14b678bb2d7fc9fc Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Mon, 10 Jan 2022 16:07:31 +0300 Subject: Tests: using modules in Go. --- test/conftest.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'test/conftest.py') diff --git a/test/conftest.py b/test/conftest.py index 689c857a..966bb8f5 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -203,9 +203,7 @@ def pytest_sessionstart(session): # discover modules from check option.available['modules']['openssl'] = check_openssl(unit['unitd']) - option.available['modules']['go'] = check_go( - option.current_dir, unit['temp_dir'], option.test_dir - ) + option.available['modules']['go'] = check_go() option.available['modules']['node'] = check_node(option.current_dir) option.available['modules']['regex'] = check_regex(unit['unitd']) -- cgit From 0f725346603f4de4473d12da502104b188ac02a4 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Mon, 11 Apr 2022 21:05:14 +0100 Subject: Tests: style. --- test/conftest.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'test/conftest.py') diff --git a/test/conftest.py b/test/conftest.py index 966bb8f5..bed56331 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -159,9 +159,7 @@ def pytest_generate_tests(metafunc): type + ' ' + available_versions[0] ) elif callable(prereq_version): - generate_tests( - list(filter(prereq_version, available_versions)) - ) + generate_tests(list(filter(prereq_version, available_versions))) else: raise ValueError( @@ -320,9 +318,7 @@ def run(request): public_dir(path) - if os.path.isfile(path) or stat.S_ISSOCK( - os.stat(path).st_mode - ): + if os.path.isfile(path) or stat.S_ISSOCK(os.stat(path).st_mode): os.remove(path) else: for attempt in range(10): @@ -520,7 +516,7 @@ def _clear_conf(sock, *, log=None): try: certs = json.loads( - http.get(url='/certificates', sock_type='unix', addr=sock,)['body'] + http.get(url='/certificates', sock_type='unix', addr=sock)['body'] ).keys() except json.JSONDecodeError: @@ -528,7 +524,9 @@ def _clear_conf(sock, *, log=None): for cert in certs: resp = http.delete( - url='/certificates/' + cert, sock_type='unix', addr=sock, + url='/certificates/' + cert, + sock_type='unix', + addr=sock, )['body'] assert 'success' in resp, 'remove certificate' @@ -554,9 +552,7 @@ def _check_fds(*, log=None): ) ps['fds'] += fds_diff - assert ( - fds_diff <= option.fds_threshold - ), 'descriptors leak main process' + assert fds_diff <= option.fds_threshold, 'descriptors leak main process' else: ps['fds'] = _count_fds(unit_instance['pid']) @@ -588,7 +584,8 @@ def _count_fds(pid): try: out = subprocess.check_output( - ['procstat', '-f', pid], stderr=subprocess.STDOUT, + ['procstat', '-f', pid], + stderr=subprocess.STDOUT, ).decode() return len(out.splitlines()) @@ -597,7 +594,8 @@ def _count_fds(pid): try: out = subprocess.check_output( - ['lsof', '-n', '-p', pid], stderr=subprocess.STDOUT, + ['lsof', '-n', '-p', pid], + stderr=subprocess.STDOUT, ).decode() return len(out.splitlines()) -- cgit From 8138d15f76b1017ba61273f69416ffbe028b0d67 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Tue, 12 Apr 2022 04:16:00 +0100 Subject: Tests: added check for zombie processes. --- test/conftest.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'test/conftest.py') diff --git a/test/conftest.py b/test/conftest.py index bed56331..904abc32 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -334,6 +334,10 @@ def run(request): _check_fds(log=log) + # check processes id's and amount + + _check_processes() + # print unit.log in case of error if hasattr(request.node, 'rep_call') and request.node.rep_call.failed: @@ -433,6 +437,16 @@ def unit_stop(): return + # check zombies + + out = subprocess.check_output( + ['ps', 'ax', '-o', 'state', '-o', 'ppid'] + ).decode() + z_ppids = re.findall(r'Z\s*(\d+)', out) + assert unit_instance['pid'] not in z_ppids, 'no zombies' + + # terminate unit + p = unit_instance['process'] if p.poll() is not None: @@ -532,6 +546,50 @@ def _clear_conf(sock, *, log=None): assert 'success' in resp, 'remove certificate' +def _check_processes(): + router_pid = _fds_info['router']['pid'] + controller_pid = _fds_info['controller']['pid'] + unit_pid = unit_instance['pid'] + + for i in range(600): + out = ( + subprocess.check_output( + ['ps', '-ax', '-o', 'pid', '-o', 'ppid', '-o', 'command'] + ) + .decode() + .splitlines() + ) + out = [l for l in out if unit_pid in l] + + if len(out) <= 3: + break + + time.sleep(0.1) + + assert len(out) == 3, 'main, router, and controller expected' + + out = [l for l in out if 'unit: main' not in l] + assert len(out) == 2, 'one main' + + out = [ + l + for l in out + if re.search(router_pid + r'\s+' + unit_pid + r'.*unit: router', l) + is None + ] + assert len(out) == 1, 'one router' + + out = [ + l + for l in out + if re.search( + controller_pid + r'\s+' + unit_pid + r'.*unit: controller', l + ) + is None + ] + assert len(out) == 0, 'one controller' + + @print_log_on_assert def _check_fds(*, log=None): def waitforfds(diff): -- cgit