diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/conftest.py | 51 | ||||
-rw-r--r-- | test/test_asgi_lifespan.py | 1 | ||||
-rw-r--r-- | test/test_java_application.py | 2 | ||||
-rw-r--r-- | test/test_node_application.py | 2 | ||||
-rw-r--r-- | test/test_proxy.py | 2 | ||||
-rw-r--r-- | test/test_proxy_chunked.py | 2 | ||||
-rw-r--r-- | test/test_static.py | 2 | ||||
-rw-r--r-- | test/test_usr1.py | 2 | ||||
-rw-r--r-- | test/unit/applications/lang/node.py | 2 | ||||
-rw-r--r-- | test/unit/utils.py | 50 |
10 files changed, 59 insertions, 57 deletions
diff --git a/test/conftest.py b/test/conftest.py index 8ca8c1d3..982e43c9 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -18,6 +18,8 @@ from unit.check.go import check_go from unit.check.node import check_node from unit.check.tls import check_openssl from unit.option import option +from unit.utils import public_dir +from unit.utils import waitforfiles def pytest_addoption(parser): @@ -298,34 +300,6 @@ def unit_stop(): p.kill() return 'Could not terminate unit' -def public_dir(path): - os.chmod(path, 0o777) - - for root, dirs, files in os.walk(path): - for d in dirs: - os.chmod(os.path.join(root, d), 0o777) - for f in files: - os.chmod(os.path.join(root, f), 0o777) - -def waitforfiles(*files): - for i in range(50): - wait = False - ret = False - - for f in files: - if not os.path.exists(f): - wait = True - break - - if wait: - time.sleep(0.1) - - else: - ret = True - break - - return ret - def _check_alerts(path=None): @@ -404,27 +378,6 @@ def stop_processes(): return 'Fail to stop process(es)' -def waitforsocket(port): - ret = False - - for i in range(50): - try: - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.connect(('127.0.0.1', port)) - ret = True - break - - except KeyboardInterrupt: - raise - - except: - sock.close() - time.sleep(0.1) - - sock.close() - - assert ret, 'socket connected' - @pytest.fixture def temp_dir(request): return unit_instance['temp_dir'] diff --git a/test/test_asgi_lifespan.py b/test/test_asgi_lifespan.py index 409634bb..43286e22 100644 --- a/test/test_asgi_lifespan.py +++ b/test/test_asgi_lifespan.py @@ -3,7 +3,6 @@ from distutils.version import LooseVersion import pytest -from conftest import public_dir from conftest import unit_stop from unit.applications.lang.python import TestApplicationPython from unit.option import option diff --git a/test/test_java_application.py b/test/test_java_application.py index 04210ebf..572e18e8 100644 --- a/test/test_java_application.py +++ b/test/test_java_application.py @@ -3,10 +3,10 @@ import os import re import time -from conftest import public_dir from conftest import skip_alert from unit.applications.lang.java import TestApplicationJava from unit.option import option +from unit.utils import public_dir class TestJavaApplication(TestApplicationJava): prerequisites = {'modules': {'java': 'all'}} diff --git a/test/test_node_application.py b/test/test_node_application.py index c8c3a444..f13a01e1 100644 --- a/test/test_node_application.py +++ b/test/test_node_application.py @@ -2,8 +2,8 @@ import re import pytest -from conftest import waitforfiles from unit.applications.lang.node import TestApplicationNode +from unit.utils import waitforfiles class TestNodeApplication(TestApplicationNode): diff --git a/test/test_proxy.py b/test/test_proxy.py index 90b6b657..975a76a0 100644 --- a/test/test_proxy.py +++ b/test/test_proxy.py @@ -6,9 +6,9 @@ import pytest from conftest import run_process from conftest import skip_alert -from conftest import waitforsocket from unit.applications.lang.python import TestApplicationPython from unit.option import option +from unit.utils import waitforsocket class TestProxy(TestApplicationPython): diff --git a/test/test_proxy_chunked.py b/test/test_proxy_chunked.py index 5529b397..73d94332 100644 --- a/test/test_proxy_chunked.py +++ b/test/test_proxy_chunked.py @@ -4,9 +4,9 @@ import socket import time from conftest import run_process -from conftest import waitforsocket from unit.applications.lang.python import TestApplicationPython from unit.option import option +from unit.utils import waitforsocket class TestProxyChunked(TestApplicationPython): diff --git a/test/test_static.py b/test/test_static.py index 1df0c902..4591aa03 100644 --- a/test/test_static.py +++ b/test/test_static.py @@ -3,9 +3,9 @@ import socket import pytest -from conftest import waitforfiles from unit.applications.proto import TestApplicationProto from unit.option import option +from unit.utils import waitforfiles class TestStatic(TestApplicationProto): diff --git a/test/test_usr1.py b/test/test_usr1.py index 3e44e4c5..44f19d23 100644 --- a/test/test_usr1.py +++ b/test/test_usr1.py @@ -2,8 +2,8 @@ import os from subprocess import call from conftest import unit_stop -from conftest import waitforfiles from unit.applications.lang.python import TestApplicationPython +from unit.utils import waitforfiles class TestUSR1(TestApplicationPython): diff --git a/test/unit/applications/lang/node.py b/test/unit/applications/lang/node.py index baccef7e..cc6d06ef 100644 --- a/test/unit/applications/lang/node.py +++ b/test/unit/applications/lang/node.py @@ -1,9 +1,9 @@ import shutil from urllib.parse import quote -from conftest import public_dir from unit.applications.proto import TestApplicationProto from unit.option import option +from unit.utils import public_dir class TestApplicationNode(TestApplicationProto): diff --git a/test/unit/utils.py b/test/unit/utils.py new file mode 100644 index 00000000..f24e9728 --- /dev/null +++ b/test/unit/utils.py @@ -0,0 +1,50 @@ +import os +import socket +import time + +import pytest + + +def public_dir(path): + os.chmod(path, 0o777) + + for root, dirs, files in os.walk(path): + for d in dirs: + os.chmod(os.path.join(root, d), 0o777) + for f in files: + os.chmod(os.path.join(root, f), 0o777) + + +def waitforfiles(*files): + for i in range(50): + wait = False + + for f in files: + if not os.path.exists(f): + wait = True + break + + if not wait: + return True + + time.sleep(0.1) + + return False + + +def waitforsocket(port): + for i in range(50): + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: + try: + sock.settimeout(5) + sock.connect(('127.0.0.1', port)) + return + + except ConnectionRefusedError: + time.sleep(0.1) + + except KeyboardInterrupt: + raise + + pytest.fail('Can\'t connect to the 127.0.0.1:' + port) + |