From 07789a23e9c513dba87b020fae2989a57955e8a6 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Sun, 6 Dec 2020 16:01:59 +0000 Subject: Tests: options moved to the separate class. This change is necessary to separate the logic and prevent possible circular dependency. --- test/test_respawn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/test_respawn.py') diff --git a/test/test_respawn.py b/test/test_respawn.py index 09a806d4..fbaad666 100644 --- a/test/test_respawn.py +++ b/test/test_respawn.py @@ -2,9 +2,9 @@ import re import subprocess import time -from conftest import option from conftest import skip_alert from unit.applications.lang.python import TestApplicationPython +from unit.option import option class TestRespawn(TestApplicationPython): -- cgit From b2e767819f04153944d525ef8d97d2f3a7a9af74 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Tue, 8 Dec 2020 14:37:33 +0000 Subject: Tests: skip_alert() converted to the fixture. --- test/test_respawn.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'test/test_respawn.py') diff --git a/test/test_respawn.py b/test/test_respawn.py index fbaad666..eef2cb56 100644 --- a/test/test_respawn.py +++ b/test/test_respawn.py @@ -2,7 +2,6 @@ import re import subprocess import time -from conftest import skip_alert from unit.applications.lang.python import TestApplicationPython from unit.option import option @@ -56,7 +55,7 @@ class TestRespawn(TestApplicationPython): assert len(re.findall(self.PATTERN_CONTROLLER, output)) == 1 assert len(re.findall(self.app_name, output)) == 1 - def test_respawn_router(self): + def test_respawn_router(self, skip_alert): pid = self.pid_by_name(self.PATTERN_ROUTER) self.kill_pids(pid) @@ -66,7 +65,7 @@ class TestRespawn(TestApplicationPython): self.smoke_test() - def test_respawn_controller(self): + def test_respawn_controller(self, skip_alert): pid = self.pid_by_name(self.PATTERN_CONTROLLER) self.kill_pids(pid) @@ -78,7 +77,7 @@ class TestRespawn(TestApplicationPython): self.smoke_test() - def test_respawn_application(self): + def test_respawn_application(self, skip_alert): pid = self.pid_by_name(self.app_name) self.kill_pids(pid) -- cgit From a0bc946db306b921fd2db909377e72bf6671e843 Mon Sep 17 00:00:00 2001 From: Tiago Natel de Moura Date: Fri, 8 Jan 2021 10:38:46 +0000 Subject: Tests: fixed test_respawn.py to act upon test processes. Running `test_respawn_` test cases on a machine with Unit daemon in background would fail tests because `ps ax` was used without filtering out other unit instances. This patch also prevents from tests killing other Unit processes not related to tests. --- test/test_respawn.py | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'test/test_respawn.py') diff --git a/test/test_respawn.py b/test/test_respawn.py index eef2cb56..ed85ee95 100644 --- a/test/test_respawn.py +++ b/test/test_respawn.py @@ -21,17 +21,17 @@ class TestRespawn(TestApplicationPython): '1', 'applications/' + self.app_name + '/processes' ) - def pid_by_name(self, name): - output = subprocess.check_output(['ps', 'ax']).decode() - m = re.search(r'\s*(\d+).*' + name, output) - return m if m is None else m.group(1) + def pid_by_name(self, name, ppid): + output = subprocess.check_output(['ps', 'ax', '-O', 'ppid']).decode() + m = re.search(r'\s*(\d+)\s*' + str(ppid) + r'.*' + name, output) + return None if m is None else m.group(1) def kill_pids(self, *pids): subprocess.call(['kill', '-9'] + list(pids)) - def wait_for_process(self, process): + def wait_for_process(self, process, unit_pid): for i in range(50): - found = self.pid_by_name(process) + found = self.pid_by_name(process, unit_pid) if found is not None: break @@ -40,7 +40,10 @@ class TestRespawn(TestApplicationPython): return found - def smoke_test(self): + def find_proc(self, name, ppid, ps_output): + return re.findall(str(ppid) + r'.*' + name, ps_output) + + def smoke_test(self, unit_pid): for _ in range(5): assert 'success' in self.conf( '1', 'applications/' + self.app_name + '/processes' @@ -50,39 +53,41 @@ class TestRespawn(TestApplicationPython): # Check if the only one router, controller, # and application processes running. - output = subprocess.check_output(['ps', 'ax']).decode() - assert len(re.findall(self.PATTERN_ROUTER, output)) == 1 - assert len(re.findall(self.PATTERN_CONTROLLER, output)) == 1 - assert len(re.findall(self.app_name, output)) == 1 + out = subprocess.check_output(['ps', 'ax', '-O', 'ppid']).decode() + assert len(self.find_proc(self.PATTERN_ROUTER, unit_pid, out)) == 1 + assert len(self.find_proc(self.PATTERN_CONTROLLER, unit_pid, out)) == 1 + assert len(self.find_proc(self.app_name, unit_pid, out)) == 1 - def test_respawn_router(self, skip_alert): - pid = self.pid_by_name(self.PATTERN_ROUTER) + def test_respawn_router(self, skip_alert, unit_pid): + pid = self.pid_by_name(self.PATTERN_ROUTER, unit_pid) self.kill_pids(pid) skip_alert(r'process %s exited on signal 9' % pid) - assert self.wait_for_process(self.PATTERN_ROUTER) is not None + assert self.wait_for_process(self.PATTERN_ROUTER, unit_pid) is not None - self.smoke_test() + self.smoke_test(unit_pid) - def test_respawn_controller(self, skip_alert): - pid = self.pid_by_name(self.PATTERN_CONTROLLER) + def test_respawn_controller(self, skip_alert, unit_pid): + pid = self.pid_by_name(self.PATTERN_CONTROLLER, unit_pid) self.kill_pids(pid) skip_alert(r'process %s exited on signal 9' % pid) - assert self.wait_for_process(self.PATTERN_CONTROLLER) is not None + assert self.wait_for_process( + self.PATTERN_CONTROLLER, unit_pid + ) is not None assert self.get()['status'] == 200 - self.smoke_test() + self.smoke_test(unit_pid) - def test_respawn_application(self, skip_alert): - pid = self.pid_by_name(self.app_name) + def test_respawn_application(self, skip_alert, unit_pid): + pid = self.pid_by_name(self.app_name, unit_pid) self.kill_pids(pid) skip_alert(r'process %s exited on signal 9' % pid) - assert self.wait_for_process(self.app_name) is not None + assert self.wait_for_process(self.app_name, unit_pid) is not None - self.smoke_test() + self.smoke_test(unit_pid) -- cgit