summaryrefslogtreecommitdiffhomepage
path: root/test/unit
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2020-12-08 14:37:25 +0000
committerAndrei Zeliankou <zelenkov@nginx.com>2020-12-08 14:37:25 +0000
commit8f916285639d7f9aac9ef03cace5e4dcbcca70cd (patch)
tree3f56dd9e0d0feaef7fb8285ccb966fb612bffc9e /test/unit
parent12a0d259a50fd6feef46aeffa0e46e193ce6bb40 (diff)
downloadunit-8f916285639d7f9aac9ef03cace5e4dcbcca70cd.tar.gz
unit-8f916285639d7f9aac9ef03cace5e4dcbcca70cd.tar.bz2
Tests: utils module introduced.
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/applications/lang/node.py2
-rw-r--r--test/unit/utils.py50
2 files changed, 51 insertions, 1 deletions
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)
+